C. Dividing the numbers
 
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The first line contains a single integer n (2 ≤ n ≤ 60 000) — the number of integers Petya has.

Output

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.

Examples
input
4
output
0
2 1 4
input
2
output
1
1 1
Note

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-规律的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces 385C Bear and Prime Numbers

    题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...

  4. Codeforces 385C Bear and Prime Numbers(素数预处理)

    Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...

  5. Codeforces Round #801 (Div. 2) C(规律证明)

    Codeforces Round #801 (Div. 2) C(规律证明) 题目链接: 传送门QAQ 题意: 给定一个\(n * m\)的矩阵,矩阵的每个单元的值为1或-1,问从\((1,1)\)开 ...

  6. Codeforces 899C - Dividing the numbers

    传送门:http://codeforces.com/contest/899/problem/C 本题是一个数学问题——集合划分. 将集合{1,2,...,n}划分成两个集合,使得两个集合的元素之和的绝 ...

  7. Dividing the numbers CodeForces - 899C (构造)

    大意: 求将[1,n]划分成两个集合, 且两集合的和的差尽量小. 和/2为偶数最小差一定为0, 和/2为奇数一定为1. 显然可以通过某个前缀和删去一个数得到. #include <iostrea ...

  8. 【Codeforces Round #452 (Div. 2) C】 Dividing the numbers

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] n为偶数. l = 1, r = n (l,r)放在一组 l++,r-- 新的l,r放在另外一组 直到l+1==r 这个时候,判断两 ...

  9. Educational Codeforces Round 8 D. Magic Numbers 数位DP

    D. Magic Numbers 题目连接: http://www.codeforces.com/contest/628/problem/D Description Consider the deci ...

随机推荐

  1. DOS中断及程序调用

    http://www.cnblogs.com/ynwlgh/archive/2011/12/12/2285017.html

  2. 51nod 1105 二分答案法标准题目

    二分答案法例题,用于练习二分答案的基本思想非常合适,包括了思维方式转换的内容(以前我们所做的一直是利用二分法求得数组元素对应指针之类,但是现在是直接对答案进行枚举). 思路是:首先对输入数组进行排序, ...

  3. Win7系统桌面便签怎么添加?

    参考:http://jingyan.baidu.com/article/ab69b270c207432ca7189f99.html Win7系统桌面便签怎么添加?有时候工作.学习忙起来就会忘记要办的事 ...

  4. 62、在app遇到全局异常时避免直接退出,如何让app接管异常处理?

    1.创建一个类为CrashHandler import android.content.Context; import android.os.Looper; import android.util.L ...

  5. Redis 配置登录密码

    1. 通过配置文件进行配置 打开 redis.conf,找到 #requirepass foobared 去掉行前的注释,并修改密码为所需的密码,保存文件 重启redis sudo service r ...

  6. 11 JVM 垃圾回收(上)

    引用计数法和可达性分析 垃圾回收,就是将已经分配出去的,但却不在使用的内存回收回来,以便再次分配.在 Java 虚拟机语境下,垃圾指的是死亡的对象所占据的堆空间.下面就总结一下如何如何辨别一个对象是否 ...

  7. Spring七大模块

    七大模块,如下: 1. Spring Core: Core封装包是框架的最基础部分,提供IOC和依赖注入特性.这里的基础概念是BeanFactory,它提供对Factory模式的经典实现来消除对程序性 ...

  8. SVD简化数据

    一,引言 我们知道,在实际生活中,采集到的数据大部分信息都是无用的噪声和冗余信息,那么,我们如何才能剔除掉这些噪声和无用的信息,只保留包含绝大部分重要信息的数据特征呢? 除了上次降到的PCA方法,本次 ...

  9. python 使用入的坑

    如测试代码,并没有将li.li_ 的交集查询出来 li=[1,2,3,4,5] li_=[2,5,6,7,9] for i in li_: if i in li: li_.remove(i) prin ...

  10. LINUX系统安装MYSQL命令

    1.下载安装包 wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz    2. ...