zoukankan      html  css  js  c++  java
  • 2020牛客暑期多校训练营(第七场)B-Mask Allocation

    B- Mask Allocation

    题意

    给你(n imes m)个口罩,要将这些口罩分成(k)份,且这(k)份口罩恰好能组成(m)(n)个口罩和(n)(m)个口罩,问(k)最小的情况下,让每份口罩数量组成的序列字典序最大。

    分析

    将题目看做在(n imes m)的矩形中染色,每次选择一个最大的正方形去染色就是最优的。

    Code

    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<iomanip>
    #include<sstream>
    #include<cstdio>
    #include<string>
    #include<vector>
    #include<bitset>
    #include<queue>
    #include<cmath>
    #include<stack>
    #include<set>
    #include<map>
    #define rep(i,x,n) for(int i=x;i<=n;i++)
    #define per(i,n,x) for(int i=n;i>=x;i--)
    #define sz(a) int(a.size())
    #define rson mid+1,r,p<<1|1
    #define pii pair<int,int>
    #define lson l,mid,p<<1
    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define se second
    #define fi first
    using namespace std;
    const double eps=1e-8;
    const int mod=1e9+7;
    const int N=1e5+10;
    const int inf=1e9;
    int T;
    int n,m;
    int main(){
        //ios::sync_with_stdio(false);
        //freopen("in","r",stdin);
        scanf("%d",&T);
        while(T--){
            scanf("%d%d",&n,&m);
            vector<int>v;
            while(n&&m){
                if(n>m) swap(n,m);
                rep(i,1,n) v.pb(n);
                m-=n;
            }
            printf("%d
    ",sz(v));
            for(int x:v) printf("%d ",x);
            puts("");
        }
        return 0;
    }
    
  • 相关阅读:
    python 4 days
    python 3 days
    python 2 days
    Git学习1-- 简介、命令使用、添加远程仓库方法
    Week2-列表、字符串方法示例
    Week2-购物车程序
    Week2-模块初识和数据类型
    Week1-作业:用户登陆程序
    Week1-Python入门教程(后续完善中)
    Intellij IDEA(eclipse设置)常用快捷键
  • 原文地址:https://www.cnblogs.com/xyq0220/p/13418260.html
Copyright © 2011-2022 走看看