find your present (2) hdoj 2095
/*
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的更多相关文章
- HDOJ 2095
find your present (2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/1024 K (Java/Oth ...
- HDU 2095 find your present (2)
HDU 2095 find your present (2) 解法一:使用set 利用set,由于只有一个为奇数次,对一个数进行查询,不在集合中则插入,在集合中则删除,最后剩下的就是结果 /* HDU ...
- HDOJ(HDU) 1563 Find your present!(异或)
Problem Description In the new year party, everybody will get a "special present".Now it's ...
- find your present (2) 2095
Problem Description In the new year party, everybody will get a "special present".Now it's ...
- 杭电 2095 find your present (2)【位运算 异或】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2095 解题思路:因为只有我们要求的那个数出现的次数为奇数,所以可以用位运算来做,两次异或同一个数最后结 ...
- hdu 2095 find your present (2) 位运算
题意:找出现次数为奇数的数 xor运算 #include <cstdio> #include <iostream> #include <algorithm> usi ...
- HDU 2095 find your present (2) (异或)
题意:给定n个数,让你找出那一个次数为1的. 析:由于题意说了,只有那一个数是奇数,所以其他的都是偶数,根据异或的性质,两个相同的数异或为0: 任何数和0异或得原数,可以很简单的做出这个题. 代码如下 ...
- HDU 2095 find your present (2) 动态链表
解题报告:输入一个n,后面紧跟着输入n个数,输入的这n个数中,除了有一个数的个数为奇数外,其它的数的个数都是偶数个,现在要你找出这个个数为奇数的这个数. 看起来好像很简单的样子,不过,这题的重点不在这 ...
- HDU 2095 find your present (2)( 位运算 )
链接:传送门 题意:给出n个数,这n个数中只有一种数出现奇数次,其他全部出现偶数次,让你找到奇数次这个数 思路:简单异或运算题 /*********************************** ...
随机推荐
- 【问题解决方案】ImportError: No module named 'pygal'
<Python编程:从入门到实践>一书,第二个项目-可视化,第四节用到pygal 安装部分用 'python -m pip install pygal==1.7' 安装,但使用时仍然报错 ...
- Docker 部署Confluence15.2
一.数据库准备 数据库版本:5.7 这里数据库并没有采用docker镜像方式,而是选择已有数据库.至于数据库安装这里不再说明. 注:我这里安装confluence时,需要在下面配置数据库信息时,在数据 ...
- CH1201 最大子序和
http://contest-hunter.org:83/contest/0x10%E3%80%8C%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9 ...
- 【THUSC2017】【LOJ2982】宇宙广播 计算几何 高斯消元
题目大意 有 \(n\) 个 \(n\) 维空间中的球,求这些球的所有公切面. 保证不会无解或有无穷多组解. \(n\leq 10\) 题解 你可以认为这是一道传统题. 记公切面为 \(a_1x_1+ ...
- SpringMvc如何获取请求头请求体的消息
对接第三方服务,说传递的POST请求中,Request Header中有需要的参数,Request Body为XML格式,包括创建消息正文和属性. 刚开始我以为可以通过 HttpServletRequ ...
- Git中.gitignore文件不起作用的解决以及Git中的忽略规则介绍
在Studio里使用Git管理代码的过程中,可以修改.gitignore文件中的标示的方法来忽略开发者想忽略掉的文件或目录,如果没有.gitignore文件,可以自己手工创建.在.gitignore文 ...
- ECMA262,JavaScript引擎,浏览器
相关阅读:https://www.cnblogs.com/970119449blog/p/8080133.html 相关阅读:https://www.jb51.net/article/75888.ht ...
- winform动态生成新窗体并添加控件执行命令
主要代码 Form nf = new Form(); ; ; nf.Width = _w; nf.Height = _h; //添加textbox TextBox tb = new TextBox() ...
- CentOS7防火墙问题
CentOS6关闭防火墙使用以下命令, //临时关闭service iptables stop//禁止开机启动chkconfig iptables off CentOS7中若使用同样的命令会报错, s ...
- BZOJ 1010: 玩具装箱toy (斜率优化dp)
Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1... ...