• lcm与gcd


    http://acm.hdu.edu.cn/showproblem.php?pid=6576
    题意:n个仓库m个工人,给出n个仓库的每天每个工人做ai件事,问如何分配m个工人到n个仓库,使得每一个仓库每天做相等数量的事。
     
    解法:求出n个仓库的ai的lcm,lcm/a[i]为该仓库所需最小工人数,相加起来判断是否为m的约数。最后结果为最小工人数乘以m/sum。

    //#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <stdio.h>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <string.h>
    #include <vector>
    #define ME(x , y) memset(x , y , sizeof(x))
    #define SF(n) scanf("%d" , &n)
    #define rep(i ,j , n) for(int i = j ; i < n ; i ++)
    #define INF  0x3f3f3f3f
    #define mod 1000000007
    #define PI acos(-1)
    using namespace std;
    typedef long long ll ;
    ll a[1009];
    ll gcd(ll a , ll b){
        if(a%b == 0) return b;
        else return gcd(b , a%b);
    }
    ll lcm(ll a , ll b){
        return a / gcd(a , b) * b;
    }

    int main()
    {
        ll n , m;
        while(cin >> n >> m)
        {
            int sum = 0 ;
            int l = 1;
            rep(i , 0 , n){
                scanf("%lld" , &a[i]);
                l = lcm(l , a[i]);
            }
            rep(i , 0 , n){
                sum += l / a[i]  ;
            }
            if(m % sum == 0){
                cout << "Yes" << endl;
                int b = m / sum ;
                rep(i , 0 , n-1){
                    cout << l/a[i]*b << " ";
                }
                cout << l / a[n-1] * b << endl;
            }else{
                cout << "No" << endl;
            }
        }


        return 0 ;
    }

     
  • 相关阅读:
    FHDe2Net:Full High Definition Demoireing Network
    Single Image Reflection Removal through Cascaded Refinement
    GFN___Gated Fusion Network for Single Image Dehazing
    127. 单词接龙 哈希表 BFS 优化建图 双向搜索
    面试题 02.08. 环路检测 快慢指针
    503. 下一个更大元素 II (暴力、单调栈)
    GINet:Graph Interaction Network for Scene Parsing
    FFDNet: Toward a Fast and Flexible Solution for CNN-Based Image Denoising
    搬家完成!
    Lucas定理
  • 原文地址:https://www.cnblogs.com/nonames/p/11252911.html
Copyright © 2020-2023  润新知