HDOJ题目2095find your present (2)(数学,异或消除)
2014-08-11 11:05
218 查看
find your present (2)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/1024 K (Java/Others)Total Submission(s): 15376 Accepted Submission(s): 5838
[align=left]Problem Description[/align]
In the new year party, everybody will 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 them will be yours.Each present has a card number on it, and
your present's card number will be the one that different from all the others, and you can assume that only one number appear odd times.For example, there are 5 present, and their card numbers are 1, 2, 3, 2, 1.so your present will be the one with the card
number of 3, because 3 is the number that different from all the others.
[align=left]Input[/align]
The input file will consist of several cases.
Each case will be presented by an integer n (1<=n<1000000, and n is odd) at first. Following that, n positive integers will be given in a line, all integers will smaller than 2^31. These numbers indicate the card numbers of the presents.n = 0 ends the input.
[align=left]Output[/align]
For each case, output an integer in a line, which is the card number of your present.
[align=left]Sample Input[/align]
5
1 1 3 2 2
3
1 2 1
0
[align=left]Sample Output[/align]
3
2
HintHint
use scanf to avoid Time Limit Exceeded
[align=left]Author[/align]
8600
[align=left]Source[/align]
HDU 2007-Spring Programming Contest - Warm Up (1)
[align=left]Recommend[/align]
8600 | We have carefully selected several similar problems for you: 2097 2094 1597 1595 1599
思路:根据异或的性质a^a=0;a^0=a;
ac代码
#include<stdio.h> int main() { int n; while(scanf("%d",&n)!=EOF,n) { int s=0; while(n--) { int num; scanf("%d",&num); s^=num; } printf("%d\n",s); } }
相关文章推荐
- hdoj 1563 Find your present!&&2095 Find your present(2) 异或运算
- hdoj 2095 find your present (2)【位运算,异或】
- hdoj_2095_Find your present (2) (位异或)
- hdoj-2095-find your present (2)【位异或】
- HDOJ 题目1799 循环多少次(数学 递推)
- HDOJ 题目4112Break the Chocolate(数学)
- Find your present (2) (位异或)
- HDOJ 题目4983 Goffi and GCD(数学,欧拉函数)
- HDU 2095 find your present (2)(简单题目)
- HDU 2095 find your present (2) (异或)
- HDOJ题目 1712 ACboy needs your help(完全背包)
- HDOJ 题目1840 Equations(水,数学)
- HDOJ题目 4503 湫湫系列故事——植树节(数学)
- HDOJ 题目2306 改革春风吹满地(数学 几何)
- HDOJ 题目2108Shape of HDU(数学)
- HDOJ题目2086 A1 = ?(数学)
- *寒假水71——find your present (2) 【位运算~异或(^)】
- HDOJ2095 ( find your present (2) ) 【异或运算】
- hdoj 夹角有多大(题目已修改,注意读题) 2076 (数学&转换)
- HDOJ题目2529shot(数学)