zoukankan      html  css  js  c++  java
  • hdu 4593 Robot

    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=4593  

    Robot

    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

    #include<algorithm>
    #include<iostream>
    #include<cstdlib>
    #include<cstring>
    #include<cstdio>
    #include<vector>
    #include<map>
    using std::map;
    using std::min;
    using std::find;
    using std::pair;
    using std::vector;
    using std::multimap;
    #define pb(e) push_back(e)
    #define sz(c) (int)(c).size()
    #define mp(a, b) make_pair(a, b)
    #define all(c) (c).begin(), (c).end()
    #define iter(c) __typeof((c).begin())
    #define cls(arr, val) memset(arr, val, sizeof(arr))
    #define cpresent(c, e) (find(all(c), (e)) != (c).end())
    #define rep(i, n) for(int i = 0; i < (int)n; i++)
    #define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
    const int N = 1010;
    const int INF = 0x3f3f3f3f;
    map<int, int> A;
    int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w+", stdout);
    #endif
        int n, v, ans;;
        while(~scanf("%d", &n)) {
            A.clear();
            rep(i, n + 1) {
                scanf("%d", &v);
                A[v]++;
                if(2 == A[v]) ans = v;
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    @Value映射到静态属性
    使用RestTemplateBuilder来实例化RestTemplate对象
    数组转String
    Springboot中mybatis配置
    pagehelper配置 多数据源自动切换数据库方言 mysql/sqlserver/oracle等数据库
    SpringBoot调用mybatis-config.xml的方法
    单元测试中模拟mvc测试对象MockMvc
    获取请求体中图片的二进制流直接解析成图片
    zk保证定时任务集群部署时单个节点执行
    Spring框架:BeanFactory容器
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4792975.html
Copyright © 2011-2022 走看看