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 }
  • 相关阅读:
    数据库
    SqlDataAdapter.Fill
    在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。如果在 IIS 中没有将虚拟目录配置为应用程序,则可能导致此错误。
    GridView控件
    已成功与服务器建立连接,但是在登录过程中发生错误
    查看存储过程代码
    vs2005 调试时出现“无法附加。绑定句柄无效”的解决办法
    验证码
    ORACLE的几个函数在MYSQL里面的简单实现
    【100题】第四十五题 雅虎面试两道题(矩阵判断、数组划分)
  • 原文地址:https://www.cnblogs.com/RRirring/p/4721753.html
Copyright © 2011-2022 走看看