Dividing the numbers CodeForces - 899C (构造)
大意: 求将[1,n]划分成两个集合, 且两集合的和的差尽量小.
和/2为偶数最小差一定为0, 和/2为奇数一定为1.
显然可以通过某个前缀和删去一个数得到.
#include <iostream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n, m, a[N];
char s[N]; int main() {
scanf("%d", &n);
int s = (1+n)*n/2, t = 0;
REP(i,1,n) {
t += i;
if (t>=s/2&&t-s/2<=i) {
vector<int> g;
int r = 0;
REP(j,1,i) if (j!=t-s/2) g.pb(j),r+=j;
int rr = s-r;
printf("%d\n%d ", abs(r-rr),int(g.size()));
for (auto &&t:g) printf("%d ",t);
return hr,0;
}
}
}
Dividing the numbers CodeForces - 899C (构造)的更多相关文章
- Codeforces Round #452 (Div. 2) C. Dividing the numbers(水)
C. Dividing the numbers Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in t ...
- Magic Numbers CodeForces - 628D
Magic Numbers CodeForces - 628D dp函数中:pos表示当前处理到从前向后的第i位(从1开始编号),remain表示处理到当前位为止共产生了除以m的余数remain. 不 ...
- UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂)
UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂) 题目链接 题目大意:假设有一个合数.然后它满足随意大于1小于n的整数a, 满足a^n%n = a;这种合数叫做Ca ...
- Codeforces 899C - Dividing the numbers
传送门:http://codeforces.com/contest/899/problem/C 本题是一个数学问题——集合划分. 将集合{1,2,...,n}划分成两个集合,使得两个集合的元素之和的绝 ...
- Codeforces Round #452 (Div. 2)-899A.Splitting in Teams 899B.Months and Years 899C.Dividing the numbers(规律题)
A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input standar ...
- codeforces 509 D. Restoring Numbers(数学+构造)
题目链接:http://codeforces.com/problemset/problem/509/D 题意:题目给出公式w[i][j]= (a[i] + b[j])% k; 给出w,要求是否存在这样 ...
- 【Codeforces Round #452 (Div. 2) C】 Dividing the numbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] n为偶数. l = 1, r = n (l,r)放在一组 l++,r-- 新的l,r放在另外一组 直到l+1==r 这个时候,判断两 ...
- #452 Div2 Problem C Dividing the numbers ( 思维 || 构造 )
题意 : 将从 1 ~ n 的数分成两组,要求两组和的差值尽可能小,并输出其中一组的具体选数情况 分析 : 如果将这 n 个数从大到小四个一组来进行选择的话那么差值就为 0 ,然后再来考虑 n%4 ! ...
- Codeforces 746G(构造)
G. ...
随机推荐
- CCF CSP 201312-2 ISBN号码
题目链接:http://118.190.20.162/view.page?gpid=T4 问题描述 试题编号: 201312-2 试题名称: ISBN号码 时间限制: 1.0s 内存限制: 256.0 ...
- 关于Axure RP软件的介绍——软件工程实践第二次个人作业
关于Axure RP软件的介绍——软件工程实践第二次个人作业 Axure RP是一个非常专业的快速原型设计的一个工具,客户提出需求,然后根据需求定义和规格.设计功能和界面的专家能够快速创建应用软件或W ...
- WEUI滚动加载
var row = 6, page = 1; var loading = false; //状态标记 $(document.body).infinite().on("infinite&quo ...
- op 和 oo 的区别
本是之前一位前辈留下的问题,因为我不是程序出身,略懂一些代码,后又查了很多人的博客,问了周围搞开发的朋友,得出以下结论: 有人这么形容OP和OO的不同:用面向过程的方法写出来的程序是一份蛋炒饭,而用面 ...
- shell的打印菜单
#!/bash/bin cat << EOF #EOF是变量,可随便设置,但标准是EOF 1)hello world. 2)你好,世界. EOF
- 1.2:Properties
文章著作权归作者所有.转载请联系作者,并在文中注明出处,给出原文链接. 本系列原更新于作者的github博客,这里给出链接. 上一节我们了解了一个Shader的基本结构,这一节,我们从 Propert ...
- Java 新建excle文件并填充模版内容
Java 新建excle文件并填充模版内容 一.JAR import java.io.BufferedReader; import java.io.File; import java.io.FileI ...
- zentao安装升级
------------------------一键安装8.4.1版本-------------------------------------1.查看操作系统版本[root@kvm-180 soft ...
- eclipse上的.properties文件中文编辑显示问题
安装 装Properties Editor插件,方法: Help --> Install New Software -->输入:http://propedit.sourceforge.jp ...
- 确定有穷自动机(DFA)的化简(最小化)
参考博客地址:https://blog.csdn.net/qq_33605778/article/details/80105658