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++ ...
随机推荐
- jQuery实现广告弹窗
首先设置一个固定的窗口位于右下角,效果如下: 代码: jQuery实现广告弹窗.html 之后将该窗口初始设为隐藏,通过代码实现3秒自动显示,5秒自动隐藏,其效果如下: <!DOCTYPE ht ...
- Spring Boot(十八):使用Spring Boot集成FastDFS
Spring Boot(十八):使用Spring Boot集成FastDFS 环境:Spring Boot最新版本1.5.9.jdk使用1.8.tomcat8.0 功能:使用Spring Boot将文 ...
- oracle 11g禁用和强制direct path read
一般在混合型环境中,大表在进行全表扫描或者走并行的时候一般会出现direct path read等待事件,如果在OLTP或者纯粹的DSS环境中,出现大量的direct path read直接路径读取, ...
- Linux CentOS 7的图形界面安装(GNOME、KDE等)
转载于:https://jingyan.baidu.com/article/0964eca26fc3b38284f53642.html 今天为大家介绍一下CentOS 7的图像界面安装(虚拟机和硬盘安 ...
- Oracle redo/undo 原理理解
一. 什么是redo(用于重做数据) redo也就是重做日志文件(redo log file),Oracle维护着两类重做日志文件:在线(online)重做日志文件和归档(archived)重做日志文 ...
- webpack --watch和supervisor的不同
webpack --watch只是热打包,也就是前端代码的热加载,要实现后端代码的热加载,也就是热部署,需要使用supervisor 如何使用热部署可以参考这里:http://www.cnblogs ...
- ODAC(V9.5.15) 学习笔记(十三)TOraMetaData
通过TOraMetaData控件获取Oracle数据库对象信息,首先需要设置MetaDataKind属性,然后设置Restrictions属性设置条件,最后通过激活数据集获取信息,演示代码如下: Me ...
- Python3 tkinter基础 Checkbutton anchor for生成多个控件并西对齐
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Django框架 (一) 虚拟环境配置及简单使用
虚拟环境 什么是虚拟环境 对真实的python解释器的一个拷贝版本 是事实有效的,可以独立存在运行解释python代码 可以在计算机上拷贝多个虚拟环境 为什么要使用虚拟环境 保证真实环境的纯净性 框架 ...
- 【做题】CF1045(ABH)
原文链接https://www.cnblogs.com/cly-none/p/9697662.html 题目当然不会做完了,这里只讲有做&会做的. A. Last chance 题意:有\(n ...