zoukankan      html  css  js  c++  java
  • HDU6576 Worker

    Worker

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

    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.

    Input

    The first line contains two integers n (1 ≤ n ≤ 1, 000), m (1 ≤ m ≤ 10^18). 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

    Source

    2019CCPC-江西省赛(重现赛)- 感谢南昌大学

    做这题要注意求最小公倍数的写法,以及用long long整型,剩下的都是赤裸裸的硬算。

    还要注意代码有一处求当前输入的所有数据的最小公倍数,具体代码上有标注。

    image

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    typedef long long ll;
    ll gcd(ll a,ll b){
        if(b==0) return a;
        return gcd(b,a%b);
    }
    ll lcm(ll a,ll b){
        return a*b/gcd(b,a%b);
    }
    int main(){
        ll n,m;
        ll a[1010];
        ll sum;
        while(scanf("%lld%lld",&n,&m)!=EOF){
            sum=0;
            ll x=1;
            for(ll i=0;i<n;i++){
                scanf("%lld",&a[i]);
                x=lcm(max(x,a[i]),min(x,a[i]));//这一处用的挺巧妙的。 
            }
            for(ll i=0;i<n;i++){
                sum+=(x/a[i]);
            }
            if(m%sum!=0) printf("No
    ");
            else {
            ll c=m/sum;
            printf("Yes
    ");
            printf("%lld",c*(x/a[0]));
            for(ll i=1;i<n;i++){
                printf(" %lld",c*(x/a[i]));
              }
              cout<<endl;
            }
        }
        return 0; 
    }
    天晴了,起飞吧
  • 相关阅读:
    Vijos训练计划 1304回文数
    18.03.03 位运算作业三则
    18.03.01 codevs1014 装箱问题
    Wikioi 1020 孪生蜘蛛 Label:Floyd最短路
    TYVJ P1004 滑雪 Label:记忆化搜索
    洛谷 P1118 数字三角形游戏 Label:dfs
    TYVJ P1015 公路乘车 &&洛谷 P1192 台阶问题 Label:dp
    洛谷 P1147 连续自然数和 Label:等差数列
    洛谷 P1019 单词接龙 Label:dfs
    洛谷 P1025 数的划分 Label:dp
  • 原文地址:https://www.cnblogs.com/jianqiao123/p/11255403.html
Copyright © 2011-2022 走看看