Duplicate Pair(异或操作)
2015-07-18 12:49
579 查看
Link:http://acm.fzu.edu.cn/problem.php?pid=1001
Problem 1001 Duplicate Pair
Accept: 4923 Submit: 23300
An array of length n, with address from 1 to n inclusive, contains entries from the set {1,2,...,n-1} and there's exactly two elements with the same value. Your task is to find out the value.
Input contains several cases.
Each case includes a number n (1<n<=10^6), which is followed by n integers.
The input is ended up with the end of file.
Your must output the value for each case, one per line.
21 141 2 3 2
12
IBM Challenge 2004.1
AC code:
Problem 1001 Duplicate Pair
Accept: 4923 Submit: 23300
Time Limit: 1000 mSec Memory Limit : 65536 KB
Problem Description
An array of length n, with address from 1 to n inclusive, contains entries from the set {1,2,...,n-1} and there's exactly two elements with the same value. Your task is to find out the value.
Input
Input contains several cases.Each case includes a number n (1<n<=10^6), which is followed by n integers.
The input is ended up with the end of file.
Output
Your must output the value for each case, one per line.
Sample Input
21 141 2 3 2
Sample Output
12
Source
IBM Challenge 2004.1AC code:
#include<iostream> #include<algorithm> #include<cmath> #include<cstdio> using namespace std; int n,t,tt,x,ans; int main(){ while(scanf("%d",&n)==1){ t=0; tt=0; while(n--){ scanf("%d",&x); t^=x; tt^=n; } ans=t^tt; printf("%d\n",ans); } return 0; }
相关文章推荐
- crossdomain 可用
- opencv中waitkey(0)不起作用
- Rails开发:Gem更换淘宝源
- Contains Duplicate
- Contains Duplicate II
- 使用Canvas和Paint自己绘制折线图
- 杭电 hdu 1151 Air Raid (二分匹配 + 最小路径覆盖)
- 安装windows7导致Ubuntu启动项消失的问题的解决
- BZOJ 1260: [CQOI2007]涂色paint( 区间dp )
- USACO Barn Repair(greedy)
- zoj 3677 Paint Erased
- TIME_WAIT状态原理
- 2015 HUAS Summer Training#1 B
- 第一周第四天([大小写变换问题][判断是否为email][求对角线的值] [生成数组][数字中添加逗号][生成10个两位随机数,然后再进行排序] [复制数组||将指定数组的指定范围复制到新的数组])
- hdu 4810 Wall Painting 位操作
- Project Euler:Problem 74 Digit factorial chains
- svn报错cleanup failed–previous operation has not finished; run cleanup if it was i
- wait和waitpid的使用和区别
- LeetCode题解:Climbing Stairs
- Selenium启动火狐浏览器后报错Plugin Container for firefox已停止工作