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个工人,每个仓库有一个派单速度,问:能否合理的分配每个工人,使得每个仓库一天的派单量相同。若能,输出分配方法 题解:求出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[];
ll gcd(ll a, ll b)//最大公约数
{
return b == ? 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 = ; i <= n; i++)
cin >> p[i];
ll temp = p[];
for (ll i = ; i <= n; i++)
{
temp = lcm(temp, p[i]);
} ll cnt = , flag = , d;
for (ll i = ; i <= n; i++)
cnt = cnt + temp / p[i];
if (m%cnt != )
flag = ;
else
d = m / cnt;
if (flag == )
{
cout << "Yes" << endl;
for (ll i = ; i <= n; i++)
{
if (i != n)
cout << temp / p[i] * d << ' ';
else
cout << temp / p[i] * d << endl;
}
}
else
cout << "No" << endl;
}
return ;
}
J - Worker的更多相关文章
- MySQL: Tree-Hierarchical query
http://dba.stackexchange.com/questions/30021/mysql-tree-hierarchical-query No problem. ...
- poj1821 Fence【队列优化线性DP】
Fence Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6122 Accepted: 1972 Description ...
- 826. Most Profit Assigning Work
https://leetcode.com/problems/most-profit-assigning-work/description/ class Solution { public: int m ...
- 使用OpenMP加快OpenCV图像处理性能 | speed up opencv image processing with openmp
本文首发于个人博客https://kezunlin.me/post/7a6ba82e/,欢迎阅读! speed up opencv image processing with openmp Serie ...
- 2019CCPC-江西省赛
目录 Contest Info Solutions A. Cotree C.Trap D.Wave F.String G. Traffic H.Rng I. Budget J. Worker K. C ...
- JXCPC 试题册
JXCPC 试题册 Input file: standard input Output file: standard output Time limit: 1s Memory limit: 256 m ...
- HDU重现赛之2019CCPC-江西省赛
本人蒟蒻,5个小时过了5道,看到好几个大佬AK,%%%%%%% http://acm.hdu.edu.cn/contests/contest_show.php?cid=868 先放大佬的题解(不是我写 ...
- C++职工管理系统
目录 职工管理系统 一. 需求 二. 创建管理类 1.创建文件 2. 头文件实现 3. 源文件实现 三. 菜单功能 1. 添加成员函数 2. 功能实现 3. 测试菜单功能 四. 退出功能 1. 提供功 ...
- Web Worker javascript多线程编程(一)
什么是Web Worker? web worker 是运行在后台的 JavaScript,不占用浏览器自身线程,独立于其他脚本,可以提高应用的总体性能,并且提升用户体验. 一般来说Javascript ...
随机推荐
- Android编程实现点击链接打开APP功能示例
本文实例讲述了Android编程实现点击链接打开APP功能.分享给大家供大家参考,具体如下: 在Android中点击链接打开APP是一个很常见的需求.例如,电商为用户发送优惠券之后经常会下发一条短信: ...
- 四、linux基础-系统目录_安装_相关命令_调度
4 系统目录-安装-版本4.1系统目录Linux的文件系统是采用级层式的树状目录结构,在此结构中的最上层是根目录“/”,然后在此目录下再创建其他的目录. 在装完Linux系统以后会自动生成一下等目录, ...
- 46 求1+2+3+...+n 静态成员函数和静态变量
题目描述 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 思路: 1)使用构造函数的方法,需要使用sta ...
- Codeforces1307B. Cow and Friend
本题的难点是可以在y轴正轴动,但也是突破点,知道x轴都是整数,那么对于任意长度来说,能到达的最短是1,最长是本身长度,那么我们就选择最长的距离,跳到一个点,使这个点为再跳就超过终点,那么就可以用2次跳 ...
- LibreOJ #6001. 「网络流 24 题」太空飞行计划
\(\quad\) 与网络流有关的最值有三个:最大流,最小费用,最小割.这道题是最小割.想了好久,终于想明白最小割应该怎么用. \(\quad\) 先找出矛盾的事物.在这道题中,两件事是矛盾的:做实验 ...
- 「快学springboot」16.让swagger帮忙写接口文档
swagger简介 官方的介绍 THE WORLD'S MOST POPULAR API TOOLING Swagger is the world's largest framework of API ...
- MySQL操作之DCL
目录 SQL语句的分类 DCL语句 SQL语句的分类 DDL(Data Definition Languages)语句:数据定义语言.这些语句定义了不同的数据段. 数据库.表.列.索引等数据库对象的定 ...
- 三 Spring对于延迟加载问题的解决
Spring提供了延迟加载问题的解决方法 什么是延迟加载? 延迟加载:lazy(懒加载) 执行到该行代码的时候不会发送语句,真正使用这个对象的属性的时候才会发送sql语句进行查询. 类级别延迟加载:指 ...
- 吴裕雄--天生自然HADOOP操作实验学习笔记:ETL案例
实验目的 熟悉hadoop生态系统 初步了解大数据点击流分析业务 学会使用hadoop进行数据分析统计 实验原理 hadoop主要有三部分,hdfs做数据存储.mapreduce做数据计算.yarn做 ...
- 【剑指Offer面试编程题】题目1522:包含min函数的栈--九度OJ
题目描述: 定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数. 输入: 输入可能包含多个测试样例,输入以EOF结束. 对于每个测试案例,输入的第一行为一个整数n(1<=n&l ...