zoukankan      html  css  js  c++  java
  • J

    Avin meets a rich customer today. He will earn 1 million dollars if he can solve a hard problem. There are n warehouses and m workers. Any worker in the i-th warehouse can handle ai orders per day. The customer wonders whether there exists one worker assignment method satisfying that every warehouse handles the same number of orders every day. Note that each worker should be assigned to exactly one warehouse and no worker is lazy when working.

    Input

    The first line contains two integers n (1 ≤ n ≤ 1, 000), m (1 ≤ m ≤ 1018). The second line contains n integers. The i-th integer ai (1 ≤ ai ≤ 10) represents one worker in the i-th warehouse can handle ai orders per day.

    Output

    If there is a feasible assignment method, print "Yes" in the first line. Then, in the second line, print n integers with the i-th integer representing the number of workers assigned to the i-th warehouse.
    Otherwise, print "No" in one line. If there are multiple solutions, any solution is accepted.

    Sample Input

    2 6
    1 2
    2 5
    1 2
    Sample Output

    Yes
    4 2
    No

    题意:n个仓库,m个工人,每个仓库有一个派单速度,问:能否合理的分配每个工人,使得每个仓库一天的派单量相同。若能,输出分配方法

    题解:求出n个派单速度的最小公倍数p,如果m%n==0,则合理分配

    #include<iostream>
    #include<algorithm>
    #include<string.h>
    #include<string>
    #define ll long long
    using namespace std;
    ll n, m;
    ll p[1005];
    ll gcd(ll a, ll b)//最大公约数
    {
        return b == 0 ? a : gcd(b, a % b);
    }
    
    ll lcm(ll a, ll b)//最小公倍数
    {
        return a / gcd(a, b) * b;
    }
    int main()
    {
        while (cin >> n >> m) 
        {
            for (ll i = 1; i <= n; i++)
                cin >> p[i];
            ll temp = p[1];
            for (ll i = 2; i <= n; i++)
            {
                temp = lcm(temp, p[i]);
            }
    
            ll cnt = 0, flag = 0, d;
            for (ll i = 1; i <= n; i++)
                cnt = cnt + temp / p[i];
            if (m%cnt != 0)
                flag = 1;
            else
                d = m / cnt;
            if (flag == 0)
            {
                cout << "Yes" << endl;
                for (ll i = 1; i <= n; i++)
                {
                    if (i != n)
                        cout << temp / p[i] * d << ' ';
                    else
                        cout << temp / p[i] * d << endl;
                }
            }
            else
                cout << "No" << endl;
        }
        return 0;
    }



  • 相关阅读:
    Linux下使用wireshark权限问题
    Ubuntu关机出错卡死 PCIe Bus Error: severity=Corrected, type=Physical Layer, id=00e5(Receiver ID)
    东南大学《操作系统》课程作业 第二章
    东南大学《操作系统》课程作业 第一章
    东南大学《操作系统》课程作业 第三章
    回溯算法
    拓扑排序之课程表问题
    C++虚函数多态
    JMETER安装及基本使用
    JMETER正则表达式提取器使用
  • 原文地址:https://www.cnblogs.com/-citywall123/p/11234481.html
Copyright © 2011-2022 走看看