首页 > 其他 > 详细

CodeForces - 899C ---Dividing the numbers

时间:2018-02-10 18:33:42      阅读:187      评论:0      收藏:0      [点我收藏+]

题目大意:给你一个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++的输入和输出,*^_^*

CodeForces - 899C ---Dividing the numbers

原文:https://www.cnblogs.com/zznu17-091041/p/8439319.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!