/*
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. Java 常见数据交换格式——xml、json、yaml

    目录 数据交换格式介绍 XML 使用DOM方式解析 使用SAX方式解析 使用DOM4J方式解析 使用JDOM方式解析 JSON 使用JSONObject方式将数据转换为JSON格式 利用JSONObj ...

  2. OpenCV4.1.0实践(3) - 图片缩放

    简单的案例: (1)通过比例进行缩放 import cv2 as cv import numpy as np # 图片缩放 img = cv.imread('images/animal.jpg', f ...

  3. Supervisor安装与使用

    一.简介 1.supervisor是什么 superviosr是一个Linux/Unix系统上进程监控和管理的工具,它由python编写,可以用pip安装.supervisor能将一个普通的命令行进程 ...

  4. Jetson TX1 SD card启动

    上网DNS /var/run/NetworkManager/resolv.conf nameserver 211.100.225.34 nameserver 219.239.26.42

  5. Mongo集群Java连接时UnknownHostException错误

    今天在 Java 连接 Mongo 集群时报了一个超时的错误,但是在本地客户端连接单节点的时候却能连上,具体报的错误如下: Caused by: com.mongodb.MongoTimeoutExc ...

  6. 关于【jq插件开发】

    很详细,原文链接:https://www.cnblogs.com/Wayou/p/jquery_plugin_tutorial.html#commentform和https://www.cnblogs ...

  7. 【XSY3344】连续段 DP 牛顿迭代 NTT

    题目大意 对于一个长度为 \(n\) 的排列 \(p\),我们称一个区间 \([l,r]\) 是连续的当且仅当 \((\max_{l\leq i\leq r}a_i)-(\min_{l\leq i\l ...

  8. Mysql 密码过期

      1. Cd D:\xampps\mysql\bin 输入命令:mysql -u root -p,回车即可进入mysql命令行界面. mysql->show database; mysql-& ...

  9. HF-01

    胡凡 本书在第2章对C语言的语法进行了详细的入门讲解,并在其中融入了部分C+的特性. 第3-5章是 入门部分. 第3章 初步训练读者最基本的编写代码能力: 第4章对 常用介绍,内容重要: 第5章是   ...

  10. spring IOC与AOP

    Spring IOC容器 spring IOC 容器有两种,分别是 BeanFactory 容器和 ApplicationContext 容器. BeanFactory如下: /*第一步,利用Clas ...