zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    函数调用本质
    互联网协议入门
    iOS开发系列-Block本质篇
    iOS组件化开发-CocoaPods简介
    版本控制-Git
    iOS开发系列-NSDate
    iOS开发系列-线程同步技术
    Python 抓取网页gb2312乱码问题
    常用正则表达式
    Java 命名规范
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11623087.html
Copyright © 2011-2022 走看看