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 ...
随机推荐
- C++基础--转string
在C++中,任意数值型转可以使用字符串流的方式来实现,如果编译器支持C++11标准的话,也可以用to_string()函数来实现. 1.to_string() to_string()包含在头文件< ...
- div 100% 填充页面
css中 html,body{ margin:0; padding:0; height:100%; }
- list的泛型
更新记录 [1]2020.02.12-21:26 1.完善内容 正文 在学习list集合时,我看到书上写list的格式时 List<E> list = new ArrayList<& ...
- DevOps专题|玩转Kubernetes网络
Kubernetes无疑是当前最火热的容器编排工具,网络是kubernetes中非常重要的一环, 本文主要介绍一些相应的网络原理及术语,以及kubernetes中的网络方案和对比. Kubernete ...
- 实现VR直播的关键技术
VR是多媒体技术发展的必然趋势,人们所使用的信息载体从最早的文字.图像,到音视频,再到用VR,将事物的描述表达推向了极致,充分满足了沉浸性.互动性和构想性三大要素的需求.随着5G的商业化运营,VR有望 ...
- 2020年9大顶级Java框架
诞生于1995年的Java,目前已在134,861个网站上广泛使用,包括ESPN.SnapDeal等.在其24年的成长史中,Java已经证明了自己是用于自定义软件开发的顶级通用编程语言. Java广泛 ...
- mac安装浏览器同步测试工具
1.安装node.js (1)打开终端,输入以下命令安装Homebrew ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebre ...
- caffe + ssd网络训练过程
參考博客:https://blog.csdn.net/xiao_lxl/article/details/79106837 1获取源代码:git clone https://github.com/wei ...
- org.springframework.test.context.junit4.SpringJUnit4ClassRunner
项目中有了spring-test的依赖,里面确实也有 org.springframework.test.context.junit4.SpringJUnit4ClassRunner 此类,但是项目就是 ...
- @Autowired注解与@Resource注解的区别(详细)
相信对现在Java码农来说,@Autowired跟@Resource并不陌生,二者都可以自动注入,但是两者的区别很多时候并没有被注意到. 一.注解的出处 @Autowired是Spring提供的注解, ...