CodeForces - 899C ---Dividing the numbers

题目大意:给你一个n,让你把1~n之间的数分为两组,使得两组之间差值最小,并打印其中任意一个分组。

思路:等差数列的前n项和判断奇偶,偶数的话最小差值肯定就是0,奇数的最小差值肯定就是1。在打印数组时,可以按照每四个一组倒着打印两端就行,还是看代码吧。

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <stack>
#define LL long long
using namespace std;
int main()
{
    LL n,i=0,j;
    scanf("%lld",&n);
    if(n*(n+1)/2%2==0)
        printf("0\n");
    else
        printf("1\n");
    printf("%d ",n/2);
    for(long long j=0,i=n;i>1;i-=2,j=!j)
    {
        cout<<i-j<<" ";
    }
    return 0;
}
View Code

后记:第一次使用C++的输入和输出,*^_^*

posted @ 2018-02-10 18:00  _簡單é  阅读(144)  评论(3编辑  收藏  举报