HDU 4593 H - Robot 水题

H – Robot
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87326#problem/H

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 <= 10 
3)

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

HINT

 

题意

有n+1个数,有一个数出现了两次,问你这个数是什么

题解

水题,map搞一搞就好了~

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)  
#define maxn 20001
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//**************************************************************************************

map<int,int> H;
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        H.clear();
        int flag=0;
        for(int i=0;i<=n;i++)
        {
            int x=read();
            H[x]++;
            if(H[x]==2)
            {
                flag=x;
            }
        }
        printf("%d\n",flag);


    }
    
}

 

    原文作者:qscqesze
    原文地址: https://www.cnblogs.com/qscqesze/p/4722416.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞