Hdu 2095 Find Your present (2)

Source: Internet
Author: User

Topic Connection

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

Hdu 2095 Find Your Present (2) Description

In the New year party, everybody'll get a "special present". Now it's your turn to get your special present, a lot of presents now putting on the desk, and only one of the them would be yo Urs. Each present have a card number on it, and your present ' s card number would be the one that different from all the others, a nd you can assume this only one number appear odd times. For example, there is 5 present, and their card numbers are 1, 2, 3, 2, 1.so your present would be is the one with the card n Umber of 3, because 3 is the number, which different from all the others.

Input

The input file is consist of several cases.
Each case would be presented by an integer n (1<=n<1000000, and n are odd) at first. Following that, n positive integers would be given in a line, all integers would smaller than 2^31. These numbers indicate the card numbers of the PRESENTS.N = 0 ends the input.

Output

For each case, output an integer in a line, which is the card number of your present.

Sample Input

5
1 1 3) 2 2
3
1 2 1
0

Sample Output

3
2

Hash

#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::p air; 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, si Zeof (arr)) #define Cpresent (C, E) (Find (All (c), (e))! = (c). End ()) #define REP (i, n) for (int i = 0; i < (int) n; i++) #defi NE tr (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) const int N = 1000007;const int INF = 0x3f3f3f3f;int Arr[n];s    truct hash_set {int tot, num[n], head[n], next[n];        inline void init (int n) {tot = 0;    Rep (i, n + 1) head[i] =-1;        } inline void Insert (int val) {int u = val% N;    Num[tot] = u, Next[tot] = Head[u], head[u] = tot++;     } inline bool Find (int val) {   int tot = 0, u = val% N;            for (int i = head[u]; ~i; i = Next[i]) {if (num[i] = = val) tot++;        if (Tot >= 2) return true;    } return false;    }}hash;int Main () {#ifdef LOCAL freopen ("In.txt", "R", stdin);    Freopen ("OUT.txt", "w+", stdout); #endif int n;        while (~SCANF ("%d", &n), N) {hash.init (n);            Rep (i, N) {scanf ("%d", &arr[i]);        Hash.insert (Arr[i]);                } Rep (I, N) {if (!hash.find (Arr[i])) {printf ("%d\n", Arr[i]);            Break }}} return 0;}

stl

#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::p air; 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, si Zeof (arr)) #define Cpresent (C, E) (Find (All (c), (e))! = (c). End ()) #define REP (i, n) for (int i = 0; i < (int) n; i++) #defi NE tr (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) const int N = 1000007;const int INF = 0x3f3f3f3f;map<int,    Int> A;map<int, Int>::iterator it;int main () {#ifdef LOCAL freopen ("In.txt", "R", stdin);    Freopen ("OUT.txt", "w+", stdout); #endif int n, v;            while (~SCANF ("%d", &n), N) {Rep (i, N) {scanf ("%d", &v);        a[v]++; } for (it = A.begin(); It! = A.end ();                ++it) {if (It->second = = 1) {printf ("%d\n", It->first);            Break    }} a.clear (); } return 0;}

Hdu 2095 Find Your present (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.