zoukankan      html  css  js  c++  java
  • HDU-4593(水题)

    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
    ",a);
    17         }
    18     }
    19     return 0;
    20 }
  • 相关阅读:
    java泛型
    转载:MSIL Instruction Table
    What if your dynamic sql statement is too long?
    自己第一个正儿八经的div+css页面
    bulk insert formatFile格式记录
    日志 20071221(WCF,using keyword)
    C++点滴
    The scripts used to generate a demo "School" database (with data)
    The typical scenarios of using "Insert" in Tsql
    如何生成任意给定区间的随机值序列
  • 原文地址:https://www.cnblogs.com/RRirring/p/4721753.html
Copyright © 2011-2022 走看看