链接:

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的更多相关文章

  1. Codeforces Round #587 (Div. 3)

    https://codeforces.com/contest/1216/problem/A A. Prefixes 题意大概就是每个偶数位置前面的ab数目要相等,很水,被自己坑了 1是没看见要输出修改 ...

  2. 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 ...

  3. Codeforces Round #587 (Div. 3) B. Shooting(贪心)

    链接: https://codeforces.com/contest/1216/problem/B 题意: Recently Vasya decided to improve his pistol s ...

  4. Codeforces Round #587 (Div. 3) A. Prefixes

    链接: https://codeforces.com/contest/1216/problem/A 题意: Nikolay got a string s of even length n, which ...

  5. Codeforces Round #587 (Div. 3) F. Wi-Fi(单调队列优化DP)

    题目:https://codeforces.com/contest/1216/problem/F 题意:一排有n个位置,我要让所有点都能联网,我有两种方式联网,第一种,我直接让当前点联网,花费为i,第 ...

  6. 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 ...

  7. Codeforces Round #587 (Div. 3) F Wi-Fi(线段树+dp)

    题意:给定一个字符串s 现在让你用最小的花费 覆盖所有区间 思路:dp[i]表示前i个全覆盖以后的花费 如果是0 我们只能直接加上当前位置的权值 否则 我们可以区间询问一下最小值 然后更新 #incl ...

  8. 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 ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. System x 服务器制作ServerGuide U盘安装Windows Server 2008 操作系统 --不格式化盘

    1.全格式化 用ServerGuide10.5 刻录成U盘 下载附件中的Rufus 3.6工具,并制作引导U盘 以管理员权限打开Rufus 3.6, 选择镜像文件 2.不格式化,仅安装C盘下载老毛桃U ...

  2. oracle 创建新用户,授权dba

    1.用有dba权限的用户登录:sys用户 2.创建一个新用户:create user abc identified by 123456; 3.授予DBA权限: grant connect,resour ...

  3. Lucene 全文检索

    基于 lucene 8 1 Lucene简介 Lucene是apache下的一个开源的全文检索引擎工具包. 1.1 全文检索(Full-text Search) 全文检索就是先分词创建索引,再执行搜索 ...

  4. pandas合并excel文件

    现在有多个excel 文件,需要对其进行合并 import pandas as pd path='' list1=[] #save data data=pd.read_excel(path,dtype ...

  5. [DEBUG] java中用Runtime调用python 简单程序输出null

    今天需要在java中调用python脚本,首先考虑的是java自带的Runtime 在ubuntu和win10下分别测试,发现win10报错 java源代码 @Test public void tes ...

  6. Vufuria入门 1 图片识别和选择

    Vufutia中的图片识别功能,底层主要是识别特征点来实现的.特征点,即那些棱角分明的点.尖锐的而不是圆滑的.对比度大的而不是小的. *** 步骤: 进入vofuria官网,登录,点击develop. ...

  7. QT 打包exe

    QT打包主要方法: 1.把无措的代码进行Release编译 2.在运行完后,找到运行后生成的目录,以下是我的文件,名为result,运行类型有两种,一种是Debug,另一种是Release,我们需要的 ...

  8. 操作系统diy-1-资料整理

    已经研三了,前段时间校招找了份内核开发的工作,正好有时间做这个以前一直想做的事情.听说写操作系统要花很多时间了解学习计算机方方面面的知识,之前也查过相关的资料,关注过mit的操作系统公开课程.这几天准 ...

  9. 什么是Sprint?

    Sprint指Scrum团队完成一定数量工作所需的短暂.固定的周期.Sprint是Scrum和敏捷的核心,找到正确的Sprint周期将帮助您的敏捷团队交付更高质量的产品. “在Scrum框架中,庞大且 ...

  10. 由[].slice.call()引发的思考

    由[].slice.call()引发的思考   经常看到大家用[].slice.call()或者Array.prototype.slice.call():  我一直是一知半解的,今天算是基本弄清楚了, ...