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

2016 省热身赛 Easy Task

时间:2016-05-03 00:29:35      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

Easy Task
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu
 

Description

You are given n integers. Your task is very easy. You should find the maximum integer a and the minimum integer b among these nintegers. And then you should replace both a and b with a-b. Your task will not be finished unless all the integers are equal.

Now the problem come, you want to know whether you can finish you task. And if you can finish the task, you want to know the final result.

Input

The first line of the input contain an integer T(T≤ 20) indicates the number of test cases.

Then T cases come. Each case consists of two lines. The first line is an integer n(2≤ n≤ 10) as the problem described. The second line contains n integers, all of them are no less than -100000 and no more than 100000.

Output

For each case you should print one line. If you can finish your task, you should print one of the n integers. Otherwise, you should print "Nooooooo!"(without quotes).

Sample Input

2
3
1 2 3
2
5 5

Sample Output

2
5
唯一注意的一点是,判断没有的情况

#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<vector>
#define maxn 55
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    int t,n,ans[maxn],c=0,f=0;
    string s,str;
    scanf("%d",&t);
    while(t--)
    {
        str="";
        f=c=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&ans[i]);
        sort(ans+1,ans+n+1);
        while(ans[1]!=ans[n])
        {
            c++;
            ans[1]=(ans[n]-ans[1]);
            ans[n]=ans[1];
            sort(ans+1,ans+n+1);
            if(c>10000000)
                break;
        }
        //cout<<c<<endl;
        if(ans[1]!=ans[n])
            printf("Nooooooo!\n");
        else
            printf("%d\n",ans[n-1]);
    }
    return 0;
}

 

 

2016 省热身赛 Easy Task

标签:

原文地址:http://www.cnblogs.com/lyf-acm/p/5453489.html

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