【异或】SOJ Find Differences
来源:互联网 发布:mac不识别u盘启动 编辑:程序博客网 时间:2024/04/25 18:26
Description
给你 n*2+1 个数 其中有 n 对是一样的 让你找出单出来的那一个Input
输入有多组数据每组数据第一行,是一个整数 n(1 <= n <= 1000000) 接下来 n*2+1 行,每行一个整数 (在 int 范围内)Output
输出单出来的那个数Sample Input
12211222Sample Output
12
分析:此题排序后查找必然超时 使用异或运算可以使相同的数抵消 所以连续异或2n+1次得到得即是答案
代码如下:
#include <cstdio>int main(){ int n,i,temp,ans; while(scanf("%d",&n)==1) { scanf("%d",&ans); for (i=1;i<=n*2;i++) { scanf("%d",&temp); ans^=temp; } printf("%d\n",ans); } return 0;}
0 0
- 【异或】SOJ Find Differences
- Differences
- SOJ 2868: find the smallest number
- SOJ-4075(n个数异或第k大的数)
- soj
- 异或解题:Find the Lost Sock
- Find your present!(异或运算)
- HDU 2095 find your present(异或)
- LeetCode 389 Find the Difference (异或)
- find your present (2)(初识异或)
- To find the differences between 2 Excel sheets in the same file
- ZOJ3432 Find the Lost Sock,异或运算
- HDU 2095 Find your present (2) (位异或)
- 异或 hdu 2095 find your present (2)
- hdu 2095 find your present (2)(位异或)
- hdu 1563简单异或Find your present!
- HDU 2095 find your present (2) 异或
- hdu - 2095 - find your present (2)(异或)
- 2014.10.02
- 数字图像之边缘检测(1)
- 检索地理位置(GeocodeService服务)
- Palindrome Partitioning II
- Surrounded Regions
- 【异或】SOJ Find Differences
- Sum Root to Leaf Numbers
- day38,page60,total390
- Longest Consecutive Sequence
- ubuntu 下eclipse 打不开
- Word Ladder
- 各种工业以太网比较(EtherCAT,EtherNet/IP,ProfiNet,Modbus-TCP,Powerlink)
- VMware上新建windows 10 虚拟机(1)
- Binary Tree Maximum Path Sum