zoukankan      html  css  js  c++  java
  • Codeforces Round #517 (Div. 2)(1~n的分配)

    题:https://codeforces.com/contest/1072/problem/C

    思路:首先找到最大的x,使得x*(x+1)/2 <= a+b

    那么一定存在一种分割使得 a1 <= a 且 b1 <= b

    证明:

    从x 到 1枚举过去,对于某个i

    如果 a >= i, 那么这个i放在第一天

    如果a < i,那么后面肯定会遇到一个a把第一天填满(因为我们是从大到小枚举的)

    所以第一天可以填满,那么除了第一天剩下的加起来也小于等于b

    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    typedef long long ll;
    const int M=1e6+5;
    int book[M];
    int main(){
        ll n,m;
        cin>>n>>m;
        ll i=1;
        while((i+1)*i<=(n+m)*2)
            i++;
        i--;
        int tot=0;
        for(int j=i;j>=1;j--){
            
            if(n>=j){
                
                book[j]=1;
                n-=j;
                tot++;
            }
            if(n==0)
                break;
        }
        cout<<tot<<endl;
        for(int j=1;j<=i;j++){
            if(book[j])
                cout<<j<<' ';
        }
        cout<<endl;
        cout<<i-tot<<endl;
        for(int j=1;j<=i;j++)
            if(!book[j])
                cout<<j<<' ';
    }
    View Code
  • 相关阅读:
    android 3dmax
    android 源码
    android 获取 图片 缩略图
    android 导入 3d 场景
    TSQL查询进阶理解SQL SERVER中的分区表
    android 画直接2
    sqlServer 加速
    android 动态壁纸
    sqlServer 2000 唯一 索引
    视频网站
  • 原文地址:https://www.cnblogs.com/starve/p/12240610.html
Copyright © 2011-2022 走看看