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. (Winform)控件中添加GIF图片以及运用双缓冲使其不闪烁以及背景是gif时使控件(如panel)变透明

    Image img = Image.FromFile(@"C:\Users\joeymary\Desktop\3.gif"); pictureBox1.Image =img.Clo ...

  2. GIt-恢复进度

    继续暂存区未完成的实践 经过了前面的实践,现在DEMO版本库应该处于master分支上,看看是不是这样. $ cd /path/to/my/workspace/demo $ git status -s ...

  3. Java 关键字volatile 与 synchronized 作用与区别

     1,volatile 它所修饰的变量不保留拷贝,直接访问主内存中的.    在Java内存模型中,有main memory,每个线程也有自己的memory (例如寄存器).为了性能,一个线程会在自己 ...

  4. Stephen 博客正式开通 【个人公众号:Stephen 】

    个人博客开通. 个人公众号:Stephen

  5. python学习-- 在django中,执行原始sql语句

    from django.shortcuts import render, redirect from news.models import Article, Column def test(reque ...

  6. c++矩阵

    这里讲的矩阵有创建矩阵,矩阵加法,矩阵乘法,输出矩阵这些功能. #include<iostream> using namespace std; template<class T> ...

  7. 基础概念:Oracle数据库

    基础概念:Oracle数据库.实例.用户.表空间.表之间的关系 数据库:Oracle数据库是数据的物理存储.这就包括(数据文件ORA或者DBF.控制文件.联机日志.参数文件).其实Oracle数据库的 ...

  8. ci日志记录

    log_message($level, $message) 参数: $level (string) -- Log level: 'error', 'debug' or 'info' $message  ...

  9. BZOJ 1192:[HNOI2006]鬼谷子的钱袋(数学)

    鬼谷子的钱袋Description鬼谷子非常聪明,正因为这样,他非常繁忙,经常有各诸侯车的特派员前来向他咨询时政.有一天,他在咸阳游历的时候,朋友告诉他在咸阳最大的拍卖行(聚宝商行)将要举行一场拍卖会 ...

  10. HDU 5884 Sort(二分答案+计算WPL的技巧)

    Sort Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...