Codeforces 899 C.Dividing the numbers-规律

 
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 }

 

 

转载于:https://www.cnblogs.com/ZERO-/p/9702989.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值