899C

来源:互联网 发布:python运维流程系统 编辑:程序博客网 时间:2024/05/17 07:06

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
02 1 4 
input
2
output
11 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.



题意:输入n,你代表是从1到n的连续自然数,把他们分成两部分,让这两部分的和差值最小。输出第一行是最小的差值,然后输出分成两部分中个数最小的那部分的个数,然后在输出每个具体的数。

题解:因为是从1 开始的自然数,每一个都比前面大1,把所有数加起来,如果sum是偶数的话,分成两部分差值是可以抵消的,差值为0,sum奇数的话,最优差值应是1.所以就两种可能。输出每个数的时候稍微麻烦一些,判断一下就可以。

自己一开想的是考虑n的奇偶性,结果大家可想而知,惨不忍睹,修改好久都不能过....参考了一下cf大神的代码,就是简短精炼....给自己说一声加油!
#include<bits/stdc++.h>using namespace std;int main(){    int n,sum,cnt,j;    while(cin>>n)    {        cnt=0;        sum=n*(n+1)/2;        if(sum%2==0) puts("0");        else puts("1");        cout<<n/2<<" ";        for(int i=n; i>1; i-=2)        {            if((++cnt)%2) j=0;            else j=1;            cout<<i-j<<" ";        }        puts("\n");    }    return 0;}