• 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 }
  • 相关阅读:
    [svc]二三层数据格式&&三层数据如何匹配路由
    [na][dhcp]dhcp细枝末节&dhcp防攻
    [docker]使用quaaga实现(rip ospf)实现主机间容器互通
    [svc]centos7安装优化最佳姿势
    [svc]gns3模拟器及探讨几个bgp问题
    [svc]ip routing和no ip routing
    [docker]macvlan实现双vlan互通
    Jmeter 日志设置---如何设置java协议中被测jar的日志?
    Jmeter java协议配置文件导入
    eclipse, Log4j配置(真心的详细~)
  • 原文地址:https://www.cnblogs.com/RRirring/p/4721753.html
Copyright © 2020-2023  润新知