• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
返回主页

Visitor

Proposal

  • 首页
  • 新随笔
  • 联系
  • 管理

【Codeforces 1031C】Cram Time

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

题意

【题解】

如果找到最大的n使得1+2+...+n<=a+b 然后第一天输出1,2.3,4....t1 这里1+2+..+t1<=a 这还远远不够。 因为可能1+2+3...+t1

【代码】

#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;
}
posted @ 2019-04-06 17:33  AWCXV  阅读(144)  评论(0)    收藏  举报
刷新页面返回顶部

公告

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3