Codeforces 1072 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的更多相关文章
- Codeforces 1072 - A/B/C/D - (Done)
链接:http://codeforces.com/contest/1072/ A - Golden Plate - [计算题] #include<bits/stdc++.h> using ...
- 【Codeforces 1031C】Cram Time
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 如果找到最大的n使得1+2+...+n<=a+b 然后第一天输出1,2.3,4....t1 这里1+2+..+t1<=a 这还远远 ...
- Codeforces Round #517 (Div. 2) C. Cram Time(思维+贪心)
https://codeforces.com/contest/1065 题意 给你a,b,让你找尽量多的自然数,使得他们的和<=a,<=b,用在a和b的自然数不能重复 思路 假如只有一个数 ...
- 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 ...
- CF-1072-C. Cram Time(贪心,数学)
CF-1072-C. Cram Time http://codeforces.com/contest/1072/problem/C 题意: 第一天有 a 小时,第二天有 b 小时.第 k 个任务需要 ...
- 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/ ...
- 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 ...
- 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 ...
- 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++ ...
随机推荐
- CRC、MD5和SHA1的区别?
什么是CRC校验?CRC即循环冗余校验码:是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定.循环冗余检查(CRC)是一种数据传输检错功能,对数据进行多项式计算,并将 ...
- gdb远程debug A syntax error in expression, near `variable)'.
今天调试有个linux环境的应用时,gdb提示A syntax error in expression, near `variable)'.,最后经查,gdb版本过低(比如7.2)或者源代码不匹配所致 ...
- 08: vue组件
1.1 初识组件 1.什么是组件 1. Html中有组件,是一段可以被复用的结构代码 2. Css中有组件,是一段可以被复用的样式 3. Js中有组件,是一段可以被复用的功能 4. Vue中也有组件, ...
- install docker swarm on centos
ref: https://sonnguyen.ws/install-docker-docker-swarm-centos7/ https://hostadvice.com/how-to/how-to- ...
- 通过shell查找访问日志中访问量最大的ip
日志格式: /Sep/::: +] /Sep/::: +] /Sep/::: +] - /Sep/::: +] - /Sep/::: +] /Sep/::: +] - /Sep/::: +] /Sep ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...
- python --- 04 列表 元组
一 .列表 在python中使用[]来描述列表, 内部元素用逗号隔开. 对数据类型没有要求 1.列表存在索引和切片. 和字符串是一样的. 2.增删改查操作 1).增加 1. .append(" ...
- tomcat8.5之后版本,远程无法登录管理页面
转载自http://jingyan.baidu.com/article/1612d500b56fa1e20e1eeed2.html 服务器采用的是linux系统. 安装tomcat在服务器上后,客户端 ...
- 在Linux系统上卸载playOnLinux
1.remove just the playonlinux package itself. sudo apt-get remove playonlinux 2.remove the playonlin ...
- topcoder srm 683 div1
problem1 link 肯定存在相邻两堆满足不会存在任何操作在这两堆之间进行.然后就成为一条链,那么只需要维护链的前缀和即可判断当前堆和前一堆之间需要多少次操作. problem2 link 对于 ...