Codeforces 899 C.Dividing the numbers-规律
1 second
256 megabytes
standard input
standard output
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of n integers should be exactly in one group.
The first line contains a single integer n (2 ≤ n ≤ 60 000) — the number of integers Petya has.
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
4
0
2 1 4
2
1
1 1
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
规律题
代码:
1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 using namespace std;
5 int main(){
6 int n;
7 while(~scanf("%d",&n)){
8 int k=n%4;
9 int t=n/4;
10 if(k==0){
11 cout<<0<<endl;
12 cout<<t*2;
13 for(int i=1;i<=t;i++)
14 cout<<" "<<i<<" "<<n-i+1;
15 cout<<endl;
16 }
17 else if(k==1){
18 cout<<1<<endl;
19 cout<<t*2+1<<" "<<1;
20 for(int i=1;i<=t;i++)
21 cout<<" "<<i+1<<" "<<n-i+1;
22 cout<<endl;
23 }
24 else if(k==2){
25 cout<<1<<endl;
26 cout<<t*2+1<<" "<<1;
27 for(int i=1;i<=t;i++)
28 cout<<" "<<i+2<<" "<<n-i+1;
29 cout<<endl;
30 }
31 else{
32 cout<<0<<endl;
33 cout<<t*2+1<<" "<<3;
34 for(int i=1;i<=t;i++)
35 cout<<" "<<i+3<<" "<<n-i+1;
36 cout<<endl;
37 }
38 }
39 return 0;
40 }
Codeforces 899 C.Dividing the numbers-规律的更多相关文章
- 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 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 ...
- Codeforces 385C Bear and Prime Numbers
题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...
- Codeforces 385C Bear and Prime Numbers(素数预处理)
Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...
- Codeforces Round #801 (Div. 2) C(规律证明)
Codeforces Round #801 (Div. 2) C(规律证明) 题目链接: 传送门QAQ 题意: 给定一个\(n * m\)的矩阵,矩阵的每个单元的值为1或-1,问从\((1,1)\)开 ...
- Codeforces 899C - Dividing the numbers
传送门:http://codeforces.com/contest/899/problem/C 本题是一个数学问题——集合划分. 将集合{1,2,...,n}划分成两个集合,使得两个集合的元素之和的绝 ...
- Dividing the numbers CodeForces - 899C (构造)
大意: 求将[1,n]划分成两个集合, 且两集合的和的差尽量小. 和/2为偶数最小差一定为0, 和/2为奇数一定为1. 显然可以通过某个前缀和删去一个数得到. #include <iostrea ...
- 【Codeforces Round #452 (Div. 2) C】 Dividing the numbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] n为偶数. l = 1, r = n (l,r)放在一组 l++,r-- 新的l,r放在另外一组 直到l+1==r 这个时候,判断两 ...
- Educational Codeforces Round 8 D. Magic Numbers 数位DP
D. Magic Numbers 题目连接: http://www.codeforces.com/contest/628/problem/D Description Consider the deci ...
随机推荐
- hihocoder 1097 最小生成树一·Prim算法
#1097 : 最小生成树一·Prim算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 最近,小Hi很喜欢玩的一款游戏模拟城市开放出了新Mod,在这个Mod中,玩家可 ...
- HDU:2846-Repository
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2846 Repository Time Limit: 2000/1000 MS (Java/Others) ...
- 动态规划:HDU1224-Free DIY Tour
Free DIY Tour Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Spark性能优化:资源调优篇
在开发完Spark作业之后,就该为作业配置合适的资源了.Spark的资源参数,基本都可以在spark-submit命令中作为参数设置.很多Spark初学者,通常不知道该设置哪些必要的参数,以及如何设置 ...
- Python 性能分析工具简介
Table of Contents 1. 性能分析和调优工具简介 1.1. Context Manager 1.2. Decorator 1.3. 系统自带的time命令 1.4. python ti ...
- 1001: [BeiJing2006]狼抓兔子(对偶图)
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 23595 Solved: 5940 Descript ...
- 12、jQuery知识总结-2
1.避免冲突 jQuery 使用 $ 符号作为 jQuery 的简介方式 <html> <head> <script type="text/javascript ...
- 使用 Pinup,PinupManager 在 XNA 中创建贴图(十七)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...
- Goole Search Auto Complete
这个项目就九章算法大数据课程的一个项目.主要分为两步: 第一步是 offline 建立 数据库 我们用两个map reduce 的data pipline 来实现. 第二步是 online显示把数据里 ...
- Leetcode 611.有效三角形的个数
有效三角形的个数 给定一个包含非负整数的数组,你的任务是统计其中可以组成三角形三条边的三元组个数. 示例 1: 输入: [2,2,3,4] 输出: 3 解释: 有效的组合是: 2,3,4 (使用第一个 ...