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

HDU-4593(水题)

时间:2015-08-11 20:53:22      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:

Robot

Problem Description
A robot is a mechanical or virtual artificial agent, usually an electro-mechanical machine that is guided by a computer program or electronic circuitry. Robots can be autonomous or semi-autonomous and range from humanoids such as Honda‘s Advanced Step in Innovative Mobility (ASIMO) and Tosy‘s TOSY Ping Pong Playing Robot (TOPIO) to industrial robots, collectively programmed ‘swarm‘ robots, and even microscopic nano robots. By mimicking a lifelike appearance or automating movements, a robot may convey a sense of intelligence or thought of its own.
Robots have replaced humans in the assistance of performing those repetitive and dangerous tasks which humans prefer not to do, or are unable to do due to size limitations, or even those such as in outer space or at the bottom of the sea where humans could not survive the extreme environments.
After many years, robots have become very intellective and popular. Glad Corporation is a big company that produces service robots. In order to guarantee the safety of production, each robot has an unique number (each number is selected from 1 to N and will be recorded when the robot is produced).
But one day we found that N+1 robots have been produced in the range of 1 to N , that‘s to say one number has been used for 2 times. Now the president of Glad Corporation hopes to find the reused number as soon as possible.
 

 

Input
Multiple cases, end with EOF.
In each case, The first line has one number N, which represents the maximum number. The next line has N +1 numbers. (All numbers are between 1 to N, and only two of them are the same.) (1 <= N <= 103)
 

 

Output
Each case, output a line with the reused number.
There are no black lines between cases.
 

 

Sample Input
2
1 2 1
1
1 1
 
 
Sample Output
1
1

 

分析:直接统计每个数字出现的次数,为2的就输出就行了。

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 using namespace std;
 5 const int maxn=1010;
 6 int h[maxn];
 7 int main()
 8 {
 9     int n;
10     while(scanf("%d",&n)!=EOF){
11         int a;
12         memset(h,0,sizeof(h));
13         for(int i=0;i<=n;i++){
14             scanf("%d",&a);
15             h[a]++;
16             if(h[a]==2) printf("%d\n",a);
17         }
18     }
19     return 0;
20 }

 

HDU-4593(水题)

标签:

原文地址:http://www.cnblogs.com/RRirring/p/4721753.html

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