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 ...
随机推荐
- svn clean up
1.下载sqlite3.exe 2.找到你项目的.svn文件,查看是否存在wc.db3.将sqlite3.exe放到.svn的同级目录4.启动cmd执行sqlite3 .svn/wc.db " ...
- 第7章:LeetCode--算法:递归问题
70. Climbing Stairs This problem is a Fibonacci problem.F(n)=F(n-1)+F(n-2);Solving this problem by r ...
- PostgreSQL-存储过程
存储过程其实就是函数,由一组 sql 语句组成,实现比较复杂的数据库操作: 存储过程 是 存储在 数据库服务器 上的,用户可以像调用 sql 自带函数一样 调用存储过程 语法解析 CREATE [OR ...
- Java 字符串比较
1.字符串比较 compareTo() 方法用于两种方式的比较: 字符串与对象进行比较. 按字典顺序比较两个字符串. 返回值 返回值是整型,它是先比较对应字符的大小(ASCII码顺序),如果第一个字符 ...
- Secret的三种形式
Secret ConfigMap这个资源对象是Kubernetes当中非常重要的一个对象,一般情况下ConfigMap是用来存储一些非安全的配置信息,如果涉及到一些安全相关的数据的话用ConfigMa ...
- Kali Linux安装AWVS漏扫工具
Acunetix是全球排名前三的漏洞发现厂商,其全称(Acunetix Web Vulnerability Scanner)AWVS是业内领先的网络漏洞扫描器,其被广泛赞誉为包括最先进的SQL注入和X ...
- 怎样获取当前网页的URL
1. document.documentURI document.documentURI; // "https://i.cnblogs.com/EditPosts.aspx?opt=1&qu ...
- poj 1224
题意:有一个5 * 6的矩阵,每个位置表示灯,1表示灯亮,0表示灯灭. 然后如果选定位置i,j点击,则位置i,j和其上下左右的灯的状态都会反转. 现在要你求出一个5 * 6的矩阵,1表示这个灯被点击过 ...
- spring——自动装配
语法:<bean id="..." class="..." autowire="byType"/> autowire属性取值如下 ...
- JDK + Tomcat 安装 + 制作自定义镜像【第 1 篇 JDK】
[第 1 篇 JDK]:https://www.cnblogs.com/del88/p/11842387.html[第 2 篇 Tomcat]:https://www.cnblogs.com/del8 ...