码迷,mamicode.com
首页 > 其他好文 > 详细

【Codeforces 1031C】Cram Time

时间:2019-04-06 19:02:16      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:color   space   ...   题意   def   大于   int   font   接下来   

【链接】 我是链接,点我呀:)
【题意】


题意

【题解】


如果找到最大的n使得1+2+...+n<=a+b
然后第一天输出1,2.3,4....t1
这里1+2+..+t1<=a
这还远远不够。
因为可能1+2+3...+t1<a
这就使得第一天还有剩余的时间没有用.
那么接下来如果继续让第二题从t1+1..n的话
可能第二题的累加和会大于b
所以我们可以这样,
让第二题再加上一天。
即输出1,2.3....t1,t1+1
然后从中删掉一个数字x=1+2+3..+t1+(t1+1)-a
显然这个数字是小于t1+1的,所以一定在第一天输出的序列中.
这样的话,第一题就能满满地用够a小时了。
然后再把x在第二题输出就好了,然后第二题从t1+2开始输出。。
注意t1=n的情况,这种情况的话,第二题就不用输出任何数字了,x也不用输出啦

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N = 1e5;

ll a,b;
ll n;
int tag[N+10];

int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> a >> b;
    //(1+n)*n/2
    for (n = 0;n*(1+n)/2<=(a+b);n++);
    n--;
    ll t1 = 0;
    for (t1 = 1;t1*(t1+1)/2<=a;t1++);
    t1--;
    if (t1*(t1+1)/2==a){
        cout<<t1<<endl;
        for (ll i = 1;i <= t1;i++){
            cout<<i<<" ";
        }
        cout<<endl;
        cout<<n-t1<<endl;
        for (ll i = t1+1;i <= n;i++){
            cout<<i<<" ";
        }
    }else{
        t1++;
        ll temp = t1*(t1+1)/2-a;
        cout<<t1-1<<endl;
        int cnt = 0;
        for (ll i = 1;i <= t1;i++)
            if (i!=temp){
                cout<<i<<" ";
                cnt++;
            }
        if (cnt>0) cout<<endl;
        cout<<n-(t1-1)<<endl;
        if (n-(t1-1)>0)cout<<temp<<" ";
        for (ll i = t1+1;i <= n;i++){
            cout<<i<<" ";
        }
    }

    return 0;
}

【Codeforces 1031C】Cram Time

标签:color   space   ...   题意   def   大于   int   font   接下来   

原文地址:https://www.cnblogs.com/AWCXV/p/10662333.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!