C - Cram Time

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

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

证明:

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

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

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

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

证毕

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head vector<int> ans1, ans2;
int main() {
fio;
int a, b;
cin >> a >> b;
int x;
for(x = ; 1LL*x*(x+)/ <= a+b; x++);
x--;
for ( ; x >= ; x--) {
if(a >= x) a -= x, ans1.pb(x);
else if(b >= x) b -= x, ans2.pb(x);
}
cout << (int) ans1.size() << endl;
for (int v : ans1) cout << v << " ";
cout << endl;
cout << (int) ans2.size() << endl;
for (int v : ans2) cout << v << " ";
cout << endl;
return ;
}

Codeforces 1072 C - Cram Time的更多相关文章

  1. Codeforces 1072 - A/B/C/D - (Done)

    链接:http://codeforces.com/contest/1072/ A - Golden Plate - [计算题] #include<bits/stdc++.h> using ...

  2. 【Codeforces 1031C】Cram Time

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 如果找到最大的n使得1+2+...+n<=a+b 然后第一天输出1,2.3,4....t1 这里1+2+..+t1<=a 这还远远 ...

  3. Codeforces Round #517 (Div. 2) C. Cram Time(思维+贪心)

    https://codeforces.com/contest/1065 题意 给你a,b,让你找尽量多的自然数,使得他们的和<=a,<=b,用在a和b的自然数不能重复 思路 假如只有一个数 ...

  4. CodeForce 517 Div 2. C Cram Time

    http://codeforces.com/contest/1072/problem/C C. Cram Time time limit per test 1 second memory limit ...

  5. CF-1072-C. Cram Time(贪心,数学)

    CF-1072-C. Cram Time http://codeforces.com/contest/1072/problem/C 题意: 第一天有 a 小时,第二天有 b 小时.第 k 个任务需要 ...

  6. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path

    http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...

  7. Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分

    Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...

  8. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)

    https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...

  9. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

随机推荐

  1. 单元测试Mock框架Powermockito 【mockito1.X】

    <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> &l ...

  2. Nginx 容器教程

    春节前,我看到 Nginx 加入了 HTTP/2 的 server push 功能,就很想试一下. 正好这些天,我在学习 Docker,就想到可以用 Nginx 容器.万一哪里改乱了,直接删掉,再重启 ...

  3. Centos 7 安装 Supervisor 及使用

    Supervisor官网链接:http://supervisord.org/installing.html 安装与设置开机启动: http://blog.csdn.net/fenglailea/art ...

  4. GCD与莫比乌斯反演的勾当

    目录 机房最后一个学懵逼钨丝的人 题目一 题目 bzoj1101 机房最后一个学懵逼钨丝的人 题目一 链接 题目没找到 求\(\sum_{1}^{n}\sum_{1}^{m}gcd(i,j)\) 式子 ...

  5. [转]web高级开发的成长之路

    读了这篇文章之后感觉蛮受启发的,在此分享一下,献给和我一样处于困惑的朋友. 正文如下: 本人也是coding很多年,虽然很失败,但也总算有点失败的心得,不过我在中国,大多数程序员都是像我一样,在一直走 ...

  6. c# Database类的使用

    参考资料http://ansonlh.iteye.com/blog/1689009 搜索:c# DatabaseFactory类

  7. 常用for循环和for in 以及for of 的区别

    用Es6对象扩展运算符(…)与rest运算符说明 function test(first,...a){ for(let val=0; val<a.length;val++){ console.l ...

  8. Ubuntu 14.04 安装 boost 1_57_0

    参考: How to build boost 1_57_0 Ubuntu platform Ubuntu 14.04 安装 boost 1_57_0 $ sudo mkdir /opt/downloa ...

  9. usart2 重映射

    今天拾起闲置很久的灰机,测试发现nrf2401坏掉,重新淘宝.还发现机上搭载的usart1坏掉,换成usart2,发现端口被电机占用,重映射到PD5,PD6 关键是后面两句不要忘记了 RCC_APB1 ...

  10. DOM中的outerHTML,innerHTML,outerText,innerText的区别

    --转自http://blog.163.com/yw_0721/blog/static/7164579720102932157759/ 简单的说innerHTML和outerHTML.innerTex ...