HDU 6576 Worker(工人)(最小公倍数)

进入报名链接)~

Worker

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 216    Accepted Submission(s): 63


 

Problem Description

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.

今天埃尔文遇见了一个阔气的顾客。如果他能解决一个难题的话,他将赚百万美刀。有n家仓库与m个工人。任何在第i个仓库的工人都可以解决ai个订单。这个顾客想知道存不存在一种分配方式满足每个仓库每天都解决相同的订单数。注意到每个工人都应该被分配到一个仓库里,每个工人都不会在工作中偷懒。

 

 

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个仓库的基本属性求一个最小公倍数,这里的意思是求得一个基本解决方案,也就是n个刚好可以达成最低运转要求的时候的人数*仓库属性的值。(或许工人数并没有达到m个,所以说是基本解决方案)。这并不是最后的答案,还需要把人数按比例扩充到m才可以。这个时候就可以单独把基本方案里的人数剔出来(最小公倍数除以仓库基本属性),然后求得基本方案所需要的人数和,如果总人数m是这个人数和的整数倍,那么这个方案就可以实现,反之不行。

如果方案可以实现了,最后只需要在基本解决方案上扩充一定整数倍的人数就可以。

//#include<pch.h>
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <cstring>
#include <cmath>
#define DETERMINATION main
#define lldin(a) scanf_s("%lld", &a)
#define println(a) printf("%lld\n", a)
#define reset(a, b) memset(a, b, sizeof(a))
const int INF = 0x3f3f3f3f;
using namespace std;
const double PI = acos(-1);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int mod = 1000000007;
const int tool_const = 19991126;
const int tool_const2 = 33;
inline ll lldcin()
{
    ll tmp = 0, si = 1;
    char c;
    c = getchar();
    while (c > '9' || c < '0')
    {
        if (c == '-')
            si = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        tmp = tmp * 10 + c - '0';
        c = getchar();
    }
    return si * tmp;
}
///Untersee Boot IXD2(1942)
/**Although there will be many obstructs ahead,
the desire for victory still fills you with determination..**/
/**Last Remote**/
ll factories[65000];
ll schemes[65000];
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a%b);
}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
int DETERMINATION()
{
        ios::sync_with_stdio(false);
        cin.tie(0), cout.tie(0);
        ll n, m;
        cin >> n >> m;
        for (int i = 1; i <= n; i++)
            cin >> factories[i];
        ll lcmans = factories[1];
        for (int i = 2; i <= n; i++)
            lcmans = lcm(factories[i],lcmans);//最小公倍数
        ll totality=0;
        for (int i = 1; i <= n; i++)
        {
            schemes[i] = lcmans / factories[i];
                totality += schemes[i];
        }//求得基本方案的人数和
        if (m%totality != 0)
            cout << "No" << endl;
        else
        {
            cout << "Yes" << endl;
            for (int i = 1; i <= n; i++)
            {
                if (i != n)
                    cout << schemes[i] * m / totality << " ";
                else
                    cout << schemes[i] * m / totality << endl;//放大一定倍数
            }
        }
        return 0;
}

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值