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;
    }
  • 相关阅读:
    python 学习——sqlalchemy 模块
    python学习——数据库基本知识mysql
    算法设计22——并行算法2 实际应用中的优化
    Perl 学习
    python学习——装饰器、生成器、迭代器
    算法设计19—— 全对最短路径 Floyd算法
    asp.net Core 使用过滤器判断请求客户端是否为移动端,并实现PC端和移动端请求映射和自动跳转
    在windows平台使用Apache James搭建邮件服务器以及使用C#向外网发送邮件
    asp.net core3.1策略授权问题
    Unity调用安卓中的方法遇到的问题
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4792975.html
Copyright © 2011-2022 走看看