HPU 18级个人训练J - Worker

这是一道关于仓库和工人订单处理的问题。给定n个仓库和m个工人,每个仓库的工人有不同的订单处理能力。任务是判断是否存在一种分配方式,使得每个仓库每天处理的订单数相同且所有工人都在工作。输出可能的分配方案或表明无解。
摘要由CSDN通过智能技术生成

J - Worker
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个工人,然后第i个车间每天每人能处理ai件订单,如果可以让每个车间每天处理的订单数相同并且没有人闲着,那么输出"Yes"并且把其中的一种方案输出出来,如果不存在这样的情况,那么就输出"No".
解题思路:这道题可以直接求出所有车间每人能处理订单数的lcm,然后用求出的lcm除以每一个车间单人可以处理的订单数保存在数组中,并且将这个数组中的所有成员相加。如果m模上这个sum为0,那么就说明有适合的方案,然后就输出,如果不为0,那么就说明没有适合的方案,就输出"No".

#include<iostream>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值