/*
author:谦智
find your present (2) hdoj 2095
法一:用暴力
法二:用map
法三:
符号是^.
异或是个位运算符号,具体是怎么操作的请百度,这里有个特性使得他能产生一种巧方法
a^a=0
0^c=c 看到上面这个式子是否你懂了呢?
没错,例如样例
5
1 1 3 2 2
如果我们用异或运算计算就是
1^1^3^2^2 由于1^1=0 2^2=0,那么就只剩下了唯一的一个3了。
如果有3个3,那么前面偶数个3由于3^3=0,势必也会只留下一个孤单的3. 那么答案就只能是那个多余的数字了。 */ //#include<iostream>
//#include<cstdio>
//using namespace std;
//int main() {
// int n;
// while (scanf("%d",&n),n) {
// int ans = 0;
// for (int i = 0; i < n; i++) {
// int x;
// scanf("%d",&x);
// ans ^= x;
// }
// printf("%d\n",ans);
// }
//} //#include<iostream>
//using namespace std;
//int main() {
// int n;
// while (cin >> n, n) {
// int ans = 0;
// for (int i = 0; i < n; i++) {
// int x;
// cin >> x;
// ans ^= x;
// }
// cout << ans << endl;
// }
//} //map 改题设定为c的输入输出
#include<iostream>
#include<map>
#include<cstdio>
using namespace std;
int main() {
int n;
while (scanf("%d",&n),n) {
map<int,int> Map;
for (int i = ; i < n; i++) {
int x;
scanf("%d",&x);
Map[x]++;
}
map<int,int>::iterator it = Map.begin();
for (; it != Map.end(); it++) {
if (it->second%) {
printf("%d\n",it->first);
break;
}
}
}
}

find your present (2) hdoj 2095的更多相关文章

  1. HDOJ 2095

    find your present (2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/1024 K (Java/Oth ...

  2. HDU 2095 find your present (2)

    HDU 2095 find your present (2) 解法一:使用set 利用set,由于只有一个为奇数次,对一个数进行查询,不在集合中则插入,在集合中则删除,最后剩下的就是结果 /* HDU ...

  3. HDOJ(HDU) 1563 Find your present!(异或)

    Problem Description In the new year party, everybody will get a "special present".Now it's ...

  4. find your present (2) 2095

    Problem Description In the new year party, everybody will get a "special present".Now it's ...

  5. 杭电 2095 find your present (2)【位运算 异或】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2095 解题思路:因为只有我们要求的那个数出现的次数为奇数,所以可以用位运算来做,两次异或同一个数最后结 ...

  6. hdu 2095 find your present (2) 位运算

    题意:找出现次数为奇数的数 xor运算 #include <cstdio> #include <iostream> #include <algorithm> usi ...

  7. HDU 2095 find your present (2) (异或)

    题意:给定n个数,让你找出那一个次数为1的. 析:由于题意说了,只有那一个数是奇数,所以其他的都是偶数,根据异或的性质,两个相同的数异或为0: 任何数和0异或得原数,可以很简单的做出这个题. 代码如下 ...

  8. HDU 2095 find your present (2) 动态链表

    解题报告:输入一个n,后面紧跟着输入n个数,输入的这n个数中,除了有一个数的个数为奇数外,其它的数的个数都是偶数个,现在要你找出这个个数为奇数的这个数. 看起来好像很简单的样子,不过,这题的重点不在这 ...

  9. HDU 2095 find your present (2)( 位运算 )

    链接:传送门 题意:给出n个数,这n个数中只有一种数出现奇数次,其他全部出现偶数次,让你找到奇数次这个数 思路:简单异或运算题 /*********************************** ...

随机推荐

  1. 'cordova' 不是内部或外部命令,也不是可运行的程序

    问题: CMD   'cordova'  不是内部或外部命令,也不是可运行的程序: 解决:配置环境变量 1.找到npm的安装路径 :如C:\Users\AppData\Roaming\npm 2.环境 ...

  2. loj121-动态图连通性

    Solution 线段树分治, 然后直接在线段树上dfs, 在进入/回溯的过程中维护并查集的merge/split. 对于split操作, 可以在merge时按秩合并, 然后利用栈记录, split时 ...

  3. Nginx CONTENT阶段 concat模块

    L67 concat_delimiter : 根据js 指定 分隔符 比如 “|” 那么每个文件分隔符为 “|” concat_types : 指定要合并文件的类型 concat_unique : s ...

  4. nginx springboot配置

    1.下载安装nginx 2.nginx.conf文件修改参数 上方是代理后的端口,代理的server.下方是需要代理的路径 3.windows 下操作指令 启动 直接点击Nginx目录下的nginx. ...

  5. Markdown 公式整理

    Cmd Markdown 公式指导手册 摘自:Cmd Markdown 公式指导手册 - 作业部落 Cmd Markdown 编辑阅读器 Cmd Markdown 简明语法手册 Cmd Markdow ...

  6. docker报错:Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

    在github上开到这样一条 于是 这两个选项换着来 具体怎么回事,咱也不知道,咱也不敢问 改完后蹭蹭的

  7. Vue状态管理之Vuex

    Vuex是专为Vue.js设计的状态管理模式.采用集中存储组件状态它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化. 1.首先让我们从一个vue的计数应用开始 ...

  8. 3d

    http://jokerwang.com/diy-3d%E6%89%93%E5%8D%B0%E6%9C%BA1-%E7%A1%AC%E4%BB%B6%E7%AF%87/

  9. Python之file

    读写文件 代码: #读写文件str = """i love China!!i hope everyone save"""#打开并书写文件f ...

  10. MFC:定时器

    1. 定时器设置 API:CWnd::SetTimer()     函数原型:UINT SetTimer(UINT nIDEvent, UINT nElapse, void (CALLBACK EXP ...