Codeforces Round #587 (Div. 3) D. Swords

Posted ydddd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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) D. Swords

Codeforces Round #587 (Div. 3) D - Swords

Codeforces Round #587 (Div. 3) C - White Sheet

Codeforces Round #587 (Div. 3) C. White Sheet

White Sheet (矩形面积模板) (Codeforces Round #587 (Div. 3) )

Codeforces Round #587 (Div. 3)