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 ...
随机推荐
- 图像分割利用KMeans生成灰度图
import numpy as np import PIL.Image as image from sklearn.cluster import KMeans def loadData(filePat ...
- Maven 项目中使用 logback
添加依赖 <dependency> <groupId>net.logstash.logback</groupId> <artifactId>logsta ...
- 第一次试水bof
BOF come from https://www.jarvisoj.com/challenges nc pwn2.jarvisoj.com 9881(远程连接) 在ubuntu16.04上进行连接, ...
- 记录—JPA生成数据库表
环境 springBoot+JPA+MySQL application-dev.yml 注意:配置中的blog数据库需要先创建,否则启动springBoot会报错 spring: #数据库连接配置 d ...
- 使用CSS3动画属性实现各种旋转跳跃
Transform字面上就是变形,改变的意思.在CSS3中transform主要包括以下几种:旋转rotate.扭曲skew.缩放scale和移动translate以及矩阵变形matrix. tran ...
- 【快学springboot】1.快速创建springboot项目
若图片查看异常,请前往掘金查看:https://juejin.im/post/5d00e793f265da1b614ff10b 使用spring initialize工具快速创建springboot项 ...
- android studio升级之后项目报错Could not find com.android.tools.build:aapt2:3.2.1-4818971
导致问题的原因为源代码根目录下的build.gradle中缺少对于google源服务器的配置(话说,貌似以前版本的都在jcenter中可以找到,最新版本的,好像没有上传到jcenter服务器了,估计是 ...
- pytorc人工神经网络Logistic regression与全连接层
//2019.10.08神经网络与全连接层1.logistics regression逻辑回归的思想是将数据利用激活函数sigmoid函数转换为0-1的概率,然后定义一定的阈值0.5,大于阈值则为一类 ...
- ubuntu 12.04 配置vsftpd 服务,添加虚拟用户,ssl加密
1.对于12.04的vsftpd 有一些bug,推荐安装版本vsftpd_2.3.5-1ubuntu2ppa1_amd64.debapt-get install python-software-pro ...
- json序列化(重要)
(1)同(2)public JsonResult JsonUserGet() { DataSet ds = Web_User.P_LG_User_Get(nUserId); return Json(J ...