zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    手动挂接NFS
    Linux中移动,复制,删除,打包排除某个目录或文件
    关于职业规划,尤其值得我们程序员学习、思考
    深入探究VC —— 链接器link.exe(4)
    用VC实现动态改变Windows的显示特性
    Windows常用控件的创建和使用
    如何添加自定义icon
    深入探究VC —— 资源编译器rc.exe(3)
    深入探究VC —— 编译器cl.exe(2)
    gluLookAt()
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9702989.html
Copyright © 2011-2022 走看看