码迷,mamicode.com
首页 > 其他好文 > 详细

hust 1471 Tobor and Numbers

时间:2014-05-17 15:20:34      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   class   code   c   

题目描述 

After the hard tasks, It’s the easy time for Y.G.Tobor and Y.D.I.

Isha is a friend of Y.D.I, as he thinks Tobor is smart too, he give Tobor a problem. This problem can describe as follow:

Tell N continuous numbers, where these N numbers are integers in the range of [-1000,1000], and the sum of these N numbers is zero.

Note:Two numbers are considered continuous iff the absolute value of difference between these two numbers is only 1.

Tobor is so smart that she solve this problem in just 10 days, and how goes on you?

输入

 

There are multiple cases, you need process to EOF.

Every line contains an integer N which is an even number in the range of (0, 50000000]

输出

 

Print case number first. Print “Yes” and these N numbers if these numbers are exits, print “No” otherwise. No blank lines between cases. See Sample Output.

The totally output size is always less than 512Kb.

样例输入

8
2

样例输出

Case 1:
Yes
1 2 1 0 -1 -2 -1 0
Case 2:
No

这个题目把我给弄晕了,一开始没注意题目的数据范围为[-1000,1000],直接写了一个,WA了,不知道为什么,唉!再看题目是发现不对,真是活该啊
bubuko.com,布布扣
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int k,n,t=0;
    while (scanf("%d",&n)!=EOF)
    {
        t++; printf("Case %d:\n",t);
        if (n%4==0)
        {
            printf("Yes\n");
            printf("0 1 0 -1");
            for (int i=2;i<=n/4;i++) printf(" 0 1 0 -1");
            printf("\n");
        }
        else printf("No\n");
    }
    return 0;
}
bubuko.com,布布扣

 

hust 1471 Tobor and Numbers,布布扣,bubuko.com

hust 1471 Tobor and Numbers

标签:des   style   blog   class   code   c   

原文地址:http://www.cnblogs.com/chensunrise/p/3730827.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!