Codeforces Round #517 (Div. 2)(1~n的分配)
题:https://codeforces.com/contest/1072/problem/C
思路:首先找到最大的x,使得x*(x+1)/2 <= a+b
那么一定存在一种分割使得 a1 <= a 且 b1 <= b
证明:
从x 到 1枚举过去,对于某个i
如果 a >= i, 那么这个i放在第一天
如果a < i,那么后面肯定会遇到一个a把第一天填满(因为我们是从大到小枚举的)
所以第一天可以填满,那么除了第一天剩下的加起来也小于等于b
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int M=1e6+;
int book[M];
int main(){
ll n,m;
cin>>n>>m;
ll i=;
while((i+)*i<=(n+m)*)
i++;
i--;
int tot=;
for(int j=i;j>=;j--){ if(n>=j){ book[j]=;
n-=j;
tot++;
}
if(n==)
break;
}
cout<<tot<<endl;
for(int j=;j<=i;j++){
if(book[j])
cout<<j<<' ';
}
cout<<endl;
cout<<i-tot<<endl;
for(int j=;j<=i;j++)
if(!book[j])
cout<<j<<' ';
}
Codeforces Round #517 (Div. 2)(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++ ...
- 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 #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) C. Cram Time(思维+贪心)
https://codeforces.com/contest/1065 题意 给你a,b,让你找尽量多的自然数,使得他们的和<=a,<=b,用在a和b的自然数不能重复 思路 假如只有一个数 ...
- Codeforces Round #517 Div. 2/Div. 1
\(n\)天没更博了,因为被膜你赛的毒瘤题虐哭了... 既然打了这次CF还是纪念一下. 看看NOIP之前,接下来几场的时间都不好.这应该是最后一场CF了,差\(4\)分上紫也是一个遗憾吧. A 给一个 ...
- Codeforces Round #517 (Div. 2)
A #include<queue> #include<cstdio> #include<cstring> #include<algorithm> #de ...
- Codeforces Round #517 Div. 1翻车记
A:真的懵逼了.冷静了半天之后决定二分一下答案,然后先a安排上尽量小的再贪心地一个个扩大.40min才过.这个做法非常怂的以代码复杂度和时间复杂度为代价换取了比较稳的正确性,事实上由于1~n可以组合出 ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)D(思维,DP,字符串)
#include<bits/stdc++.h>using namespace std;char c[2007][2007];char ans[4007];int s[2007][2007] ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- python格式字符
- 网络基础:OSI 七层模型、TCP/IP 四层模型
1.Internet历史 1. 1968年由美国ARPA机构提出"资源共享计算机网络”,让ARPA的计算机互联起来,叫做阿帕网;2. 1974年,第一个TCP协议详细说明发布了.3. 一个 ...
- leetcode - 两数之和Ⅳ 输入BST(653)
题目描述:给定一个二叉搜索树和一个目标结果,如果 BST 中存在两个元素且它们的和等于给定的目标结果,则返回 true. 解题思路:根据二叉搜索树的特点,对二叉搜索树进行中序遍历可以得到一个从小到达排 ...
- 语句:{% url menu.url_name %}的作用
语句: {% url menu.url_name %} 表示跳转,上面的menu.url_name意思是menu表的url_name字段 如果menu表的url_name字段的值是sales_dash ...
- OI常用模板
long long qpow(long long a,long long b,int mod) { ; while (b) { ) res=res*a%mod; a=a*a%mod; b>> ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习:运算符
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 用Python读取一个文本文件并统计词频
刚刚在写文章时360浏览器崩溃了,结果内容还是找回来了,感谢博客园的自动保存功能!!! ------------恢复内容开始------------ 最近在学习Python,自己写了一个小程序,可以从 ...
- python刷LeetCode:21. 合并两个有序链表
难度等级:简单 题目描述: 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4输出:1 ...
- [GXYCTF2019]Ping Ping Ping
0x00 知识点 命令执行变量拼接 /?ip=127.0.0.1;a=g;cat$IFS$1fla$a.php 过滤bash用sh执行 echo$IFS$1Y2F0IGZsYWcucGhw|base6 ...
- part5 城市页面列表开发
1.配置路由 先在router文件夹中,创建一个路由.引入组件 { path: '/city', name: 'HelloCity', component: city, meta: { name: ' ...