ID
2016-12-11 18:16
369 查看
C.ID
Time Limit: 1000 MS Memory Limit: 1000000 K
Total Submit: 1421 (405 users) Total Accepted: 264 (247 users) Special Judge: No
Description
It is very cold in Harbin in the winter, but it is pretty warm in the Zhengxin Building. Today is Saturday, Teacher ABG want to play a trick on the only one student called NWL because he didn’t finish the MOOC.
At the beginning, every student is in the building. The teacher calls some students to sweep the snow on the playground out of the building, and sometimes he also call some students who are on the playground back to the building. At last, teacher ABG wants
to leave only one student, NWL, on the playground out of the building. It means that the teacher ABG calls NWL’s ID ODD times, but called other students’ ID EVEN times, maybe more than twice. Now give you the list describing the students’ ID which the teacher
called in order, please tell us NWL’s ID.
Input
The first line is an integer T, describes the number of tests. Then T tests.
In each test, the first line is an integer N, describes the number of IDs on the list.
Then followed N lines, each line contains an integer M, describes one ID on the list.
Output
T lines. Each line, an integer, the NWL’s ID.
Sample Input
3
3
1140310000
1140310000
1140310000
1
1140310002
5
1
2
2
2
2
Sample Output
1140310000
1140310002
1
Hint
1<=T<=10
1<=N<=1,000,000
1<=M<=1,159,999,999
The sum of N in the input file is no more than 3,000,000, all the input are integers and correct.
题意:这道题的意思就是找到那一个唯一的出现次数为奇数的数。
题解:这道题有两道解法,一种就是一个一个找,当找到那个出现次数为奇数的数时,就跳出来并输出。另一种是用按位异或运算,s=s^n,其实就是将出现次数为偶数的那个数给消去,将那个出现次数为奇数的输出来。
Time Limit: 1000 MS Memory Limit: 1000000 K
Total Submit: 1421 (405 users) Total Accepted: 264 (247 users) Special Judge: No
Description
It is very cold in Harbin in the winter, but it is pretty warm in the Zhengxin Building. Today is Saturday, Teacher ABG want to play a trick on the only one student called NWL because he didn’t finish the MOOC.
At the beginning, every student is in the building. The teacher calls some students to sweep the snow on the playground out of the building, and sometimes he also call some students who are on the playground back to the building. At last, teacher ABG wants
to leave only one student, NWL, on the playground out of the building. It means that the teacher ABG calls NWL’s ID ODD times, but called other students’ ID EVEN times, maybe more than twice. Now give you the list describing the students’ ID which the teacher
called in order, please tell us NWL’s ID.
Input
The first line is an integer T, describes the number of tests. Then T tests.
In each test, the first line is an integer N, describes the number of IDs on the list.
Then followed N lines, each line contains an integer M, describes one ID on the list.
Output
T lines. Each line, an integer, the NWL’s ID.
Sample Input
3
3
1140310000
1140310000
1140310000
1
1140310002
5
1
2
2
2
2
Sample Output
1140310000
1140310002
1
Hint
1<=T<=10
1<=N<=1,000,000
1<=M<=1,159,999,999
The sum of N in the input file is no more than 3,000,000, all the input are integers and correct.
题意:这道题的意思就是找到那一个唯一的出现次数为奇数的数。
题解:这道题有两道解法,一种就是一个一个找,当找到那个出现次数为奇数的数时,就跳出来并输出。另一种是用按位异或运算,s=s^n,其实就是将出现次数为偶数的那个数给消去,将那个出现次数为奇数的输出来。
#include<stdio.h> int n,t,x,s; int main() { scanf("%d",&t); while(t--) { s=0; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&x); s^=x; } printf("%d\n",s); } return 0; }
相关文章推荐
- BZOJ1070 修车(zkw费用流 or spfa费用流)
- 读懂hadoop、hbase、hive、spark分布式系统架构
- 1004. 成绩排名 (20)
- angular使用select时要注意的坑
- js中a标签里href="javascript:void(0)"的用途
- 软件开发的三重门
- poj 3511 Fermat's Christmas Theorem 筛素数
- cv2.flip.frame.py 从摄像头中捕获视频,沿水平方向旋转每一帧并保存它
- CCS5导入工程时出错:Issues that may require your attention were encountered while importing the projects
- 使用别人demo需要复制的东西
- 在本地创建SQLite数据库存储数据
- 利用yarn多队列实现hadoop资源隔离
- gulp+webpack+angular1的一点小经验(第三部分使用一些angular1的插件ui-bootstrap与highcharts)
- SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
- gulp+webpack+angular1的一点小经验(第三部分使用一些angular1的插件ui-bootstrap与highcharts)
- 纯JS实现排列整齐的数据表格
- Java 事件监听原理及Demo实现
- 【USACO2008NOV】采购干草——会做的题目做错才可惜_耀晨SYW
- ORACLE 连接SQLSERVER 数据库备忘
- 1.jQuery选择器和事件