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\n", ans);
    }
    return 0;
}
时间: 2024-12-25 21:09:09

hdu 4593 Robot的相关文章

[ACM] HDU 4576 Robot (概率DP,滚动数组)

Robot Problem Description Michael has a telecontrol robot. One day he put the robot on a loop with n cells. The cells are numbered from 1 to n clockwise. At first the robot is in cell 1. Then Michael uses a remote control to send m commands to the ro

HDU 4576 Robot(概率题)

Robot Problem Description Michael has a telecontrol robot. One day he put the robot on a loop with n cells. The cells are numbered from 1 to n clockwise. At first the robot is in cell 1. Then Michael uses a remote control to send m commands to the ro

HDU 1035 Robot Motion Union Find 并查集题解

本题的类型我一看就想到使用并查集解了,因为要查找是否有环,这是并查集的典型用法. 但是由于本题数据实在是太水了,故此有人使用直接模拟都过了.这让本题降了个档次. 这里使用并查集解.而且可以根据需要简化并查集函数,代码还是很好打的. #include <stdio.h> #include <vector> #include <string.h> #include <algorithm> #include <iostream> #include &l

HDU 3150 Robot Roll Call – Cambot…Servo…Gypsy…Croooow(map)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3150 Problem Description Mystery Science Theater 3000 is about to start, which means it's time for "Robot Roll Call", where the name of each robot is called out, as per the list received from Earth.

HDU 1036 Robot Motion 深搜

 Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are N north (up the page) S south (down the page) E east (t

HDU 5673 Robot 卡特兰数

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5673 题目描述: 一个人从原点开始向右走, 要求N秒后回到原点, 且过程中不能到负半轴, 人有两种操作, 走动或者停止, 问总共有多少种方案? 解题思路: 类似于括号匹配问题, 和那个我去年这个时候接触到的最裸的不能越过对角线的正方形走到对角问题, 卡特兰数, 从2开始枚举走动步数, 然后剩下的就是不动的步数, 用不动的步数做个填充就可以了, 设计到取模, 需要逆元 代码: #include <i

hdu 5673 Robot 卡特兰数+逆元

Robot Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description There is a robot on the origin point of an axis.Every second, the robot can move right one unit length or do nothing.If the robot is on the

[ACM] hdu 1035 Robot Motion (模拟或DFS)

Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are N north (up the page) S south (down t

HDU 1035 [Robot Motion] 模拟 记忆

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1035 题目大意:给出一个地图,每个点都指定下一步的方向.问移动情况(何时走出地图或几步后进入多长的循环) 关键思想:模拟+记忆化.我的做法是访问过的点vis置1,往后每走一步,走过的所有点vis++,因为每个点都可能是循环的节点.后面回到一个vis>1的点,vis-1就是循环长度了.(也可以记录到每个点的步数,最后点的步数差值就是循环长度) 代码如下 //模拟 记忆.可优化 #include <i