Codeforces Round #587 (Div. 3) D. Swords
链接:
https://codeforces.com/contest/1216/problem/D
题意:
There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some single type. Note that different people might have taken different types of swords. Note that the values x,y and z are unknown for you.
The next morning the director of the theater discovers the loss. He counts all swords — exactly ai swords of the i-th type are left untouched.
The director has no clue about the initial number of swords of each type in the basement, the number of people who have broken into the basement and how many swords each of them have taken.
For example, if n=3, a=[3,12,6] then one of the possible situations is x=12, y=5 and z=3. Then the first three people took swords of the first type and the other two people took swords of the third type. Note that you don't know values x,y and z beforehand but know values of n and a.
Thus he seeks for your help. Determine the minimum number of people y, which could have broken into the theater basement, and the number of swords z each of them has taken.
思路:
将最大值设为x, 求出x-每个值的gcd, 就是每个人能拿的最大值.
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2e5+10;
LL a[MAXN];
int n;
int main()
{
cin >> n;
LL gcd = 0, mmax = 0;
for (int i = 1;i <= n;i++)
cin >> a[i], mmax = max(mmax, a[i]);
for (int i = 1;i <= n;i++)
gcd = __gcd(gcd, mmax-a[i]);
LL num = 0;
for (int i = 1;i <= n;i++)
num += (mmax-a[i])/gcd;
cout << num << ' ' << gcd << endl;
return 0;
}
Codeforces Round #587 (Div. 3) D. Swords的更多相关文章
- Codeforces Round #587 (Div. 3)
https://codeforces.com/contest/1216/problem/A A. Prefixes 题意大概就是每个偶数位置前面的ab数目要相等,很水,被自己坑了 1是没看见要输出修改 ...
- Codeforces Round #587 (Div. 3) C. White Sheet
链接: https://codeforces.com/contest/1216/problem/C 题意: There is a white sheet of paper lying on a rec ...
- Codeforces Round #587 (Div. 3) B. Shooting(贪心)
链接: https://codeforces.com/contest/1216/problem/B 题意: Recently Vasya decided to improve his pistol s ...
- Codeforces Round #587 (Div. 3) A. Prefixes
链接: https://codeforces.com/contest/1216/problem/A 题意: Nikolay got a string s of even length n, which ...
- Codeforces Round #587 (Div. 3) F. Wi-Fi(单调队列优化DP)
题目:https://codeforces.com/contest/1216/problem/F 题意:一排有n个位置,我要让所有点都能联网,我有两种方式联网,第一种,我直接让当前点联网,花费为i,第 ...
- Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}
C. White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle ...
- Codeforces Round #587 (Div. 3) F Wi-Fi(线段树+dp)
题意:给定一个字符串s 现在让你用最小的花费 覆盖所有区间 思路:dp[i]表示前i个全覆盖以后的花费 如果是0 我们只能直接加上当前位置的权值 否则 我们可以区间询问一下最小值 然后更新 #incl ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- javaSE总结(一)-java数据类型和运算符
一.注释 (1)单行注释: // (2)多行注释:/* */ (3)文档注释:/** */ 二.标识符和关键字 (1)分隔符:分号; 花括号{} 方括号[] 圆括号() 空格 圆点(.) ...
- IPv4
1.IPv4分类地址 PC0(192.168.0.1) 和PC1(172.168.0.1)如果要ping通的话需要设置各自网关 PC0 设置IP 和 默认网关=路由器设置IP 2.Gigabit ...
- idea 如何加入插件SonarLint
idea 如何加入插件SonarLint IDEA的插件安装有两种方法:一是在线安装:二是离线安装,即将插件的安装包下载以后从本地安装. 一.在线安装的过程: 1.打开IDEA ...
- Django Rest Framework 安装
1. 环境要求 Python (3.5, 3.6, 3.7): 查看 python版本:python -V Django (1.11, 2.0, 2.1, 2.2) 查看django版本:pip li ...
- LASSO回归与L1正则化 西瓜书
LASSO回归与L1正则化 西瓜书 2018年04月23日 19:29:57 BIT_666 阅读数 2968更多 分类专栏: 机器学习 机器学习数学原理 西瓜书 版权声明:本文为博主原创文章,遵 ...
- HTTP协议探究(二):代理、网关和隧道
一 复习与目标 1 复习 缓存目的:减轻服务器压力,不重复请求相同的内容 缓存位置:浏览器或中间代理 相关状态码:200或403 相关首部: etag和since-none-match.last-mo ...
- regex 正则分割字符串
string _content=adak.sjdkajskj爱25教:师的656教案时; string en=@"\.|56|25";//单个[asj]分别以a,s,j为分隔符. ...
- PLSQL PL/SQL Developer Oracle 使用技巧 常用设置 卡顿问题 病毒防范( 附带:配置文件)
相关工具版本: PL/SQL Developer: 9.0.4.1644 Oracle : Oracle Database 10g Enterprise Edition Release 10.2.0. ...
- QT打开文件或文件夹或网络地址
打开文件或文件夹 如果是文件或文件夹 必须带file:/// 后面可以是文件(夹)的绝对路径 QDesktopServices::openUrl(QUrl("file:///C:/Docum ...
- JDK + Tomcat 安装 + 制作自定义镜像【第 3 篇 系统镜像】
[第 1 篇 JDK]:https://www.cnblogs.com/del88/p/11842387.html[第 2 篇 Tomcat]:https://www.cnblogs.com/del8 ...