zoj 3844 Easy Task(水题)
2015-01-11 20:37
363 查看
题目链接
Easy Task
Time Limit: 2 Seconds
Memory Limit: 65536 KB
You are given n integers. Your task is very easy. You should find the maximum integer
a and the minimum integer b among these n integers. 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.
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.
n integers. Otherwise, you should print "Nooooooo!"(without quotes).
题意:n个数字,每次操作找出最大的数和最小的数,并把他们替换成(最大数和最小数之差)。一直操作,直至所有数字都相同。输出最后的数字。如果无解输出NOOOOO!。
题解:显然是没有无解的情况的,由于n<=10。所以直接暴力就好了。
代码如下:
Easy Task
Time Limit: 2 Seconds
Memory Limit: 65536 KB
You are given n integers. Your task is very easy. You should find the maximum integer
a and the minimum integer b among these n integers. 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 then integers. Otherwise, you should print "Nooooooo!"(without quotes).
Sample Input
2 3 1 2 3 2 5 5
Sample Output
2 5
题意:n个数字,每次操作找出最大的数和最小的数,并把他们替换成(最大数和最小数之差)。一直操作,直至所有数字都相同。输出最后的数字。如果无解输出NOOOOO!。
题解:显然是没有无解的情况的,由于n<=10。所以直接暴力就好了。
代码如下:
#include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> #include<string> #include<queue> #include<stack> #include<map> #include<set> #include<stdlib.h> #include<vector> #define inff 0x3fffffff #define nn 1100 #define mod 1000000007 typedef long long LL; const LL inf64=inff*(LL)inff; using namespace std; int n; int a[15]; int main() { int t,i; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); } int mx,mn,id1,id2; while(1) { mx=-inff,mn=inff; for(i=1;i<=n;i++) { if(a[i]>mx) { mx=a[i]; id1=i; } if(a[i]<mn) { mn=a[i]; id2=i; } } if(mn==mx) break; a[id1]=mx-mn; a[id2]=mx-mn; } printf("%d\n",mx); } return 0; }
相关文章推荐
- [ACM] ZOJ 3844 Easy Task (模拟+哈希)
- 哈希--ZOJ - 3844 Easy Task
- ZOJ 3844 Easy Task
- 【ZOJ 3844】Easy Task
- ZOJ 3844 Easy Task
- zoj 3844 easy task
- ZOJ 3844 Easy Task
- ZOJ 3844 Easy Task(暴力)
- ZOJ 3844 Easy Task(模拟+哈希 | 暴力)
- ZOJ :: Easy Task
- ZOJ 1494 Climbing Worm 数学水题
- ZOJ 2165 Red and Black(DFS,水题)
- ZOJ 2969 Easy Task
- zoj 2514水题
- zoj 2443 水题。。。
- ZOJ Problem Set - 3023 (水题)
- ZOJ Problem Set - 2969 Easy Task
- zoj 2812 Quicksum 水题
- zoj 1730 Crazy Tea Party(水题吗?我不会啊!!!)
- ZOJ 3622 —— Magic Number(水题)