HDU 2095 find your present (2) (异或)
题意:给定n个数,让你找出那一个次数为1的。
析:由于题意说了,只有那一个数是奇数,所以其他的都是偶数,根据异或的性质,两个相同的数异或为0;
任何数和0异或得原数,可以很简单的做出这个题。
代码如下:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <map> using namespace std; int main(){
int n, x;
while(~scanf("%d", &n) && n){
scanf("%d", &x);
int ans = x;
for(int i = 1; i < n; ++i){
scanf("%d", &x);
ans ^= x;
}
printf("%d\n", ans);
}
return 0;
}
HDU 2095 find your present (2) (异或)的更多相关文章
- HDU 2095 find your present (2)
HDU 2095 find your present (2) 解法一:使用set 利用set,由于只有一个为奇数次,对一个数进行查询,不在集合中则插入,在集合中则删除,最后剩下的就是结果 /* HDU ...
- HDU 2095 find your present (2) 动态链表
解题报告:输入一个n,后面紧跟着输入n个数,输入的这n个数中,除了有一个数的个数为奇数外,其它的数的个数都是偶数个,现在要你找出这个个数为奇数的这个数. 看起来好像很简单的样子,不过,这题的重点不在这 ...
- HDU 2095 find your present (2)( 位运算 )
链接:传送门 题意:给出n个数,这n个数中只有一种数出现奇数次,其他全部出现偶数次,让你找到奇数次这个数 思路:简单异或运算题 /*********************************** ...
- hdu 2095 find your present (2) 位运算
题意:找出现次数为奇数的数 xor运算 #include <cstdio> #include <iostream> #include <algorithm> usi ...
- HDU.2095(异或运算)
find your present (2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 杭电 2095 find your present (2)【位运算 异或】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2095 解题思路:因为只有我们要求的那个数出现的次数为奇数,所以可以用位运算来做,两次异或同一个数最后结 ...
- HDOJ(HDU) 1563 Find your present!(异或)
Problem Description In the new year party, everybody will get a "special present".Now it's ...
- hdu 2095
ps:真是日了狗...英语渣渣理解题目不行,开了个100W数组来算,还优化了下时间,还是超时了,看了题解才知道用异或. N个数异或,会得出其中是奇数的一个.比如 1^1^3^2^2 = 3. 1^ ...
- hdu 1563 Find your present!
Find your present! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
随机推荐
- tensorflow笔记之softmax_cross_enropy
tf.nn.sparse_softmax_cross_entropy_with_logits() 当正确结果只有一个时,可以加速计算,比如MNIST数字识别,每张图片中仅包含一个数字,所以可以使用这个 ...
- 一个js程序:离下一个圣诞节还有多少天?
话不多说上代码: //离下一个圣诞节还有多少天 var christ=new Date(); christ.setMonth(11); christ.setDate(25); var year=now ...
- linux文件格式转换:<U+FEFF> character showing up in files. How to remove them?
You can easily remove them using vim, here are the steps: 1) In your terminal, open the file using v ...
- Data Guard 介绍
- Mysql通过SQL脚本复制表
create table if not exists t_dest like t_src 其中,t_src是要复制的原始表,t_dest是要创建的新表.
- HttpClient 4 和 HttpClient 3 超时
HttpClient 4: 连接超时: httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,6000 ...
- thymeleaf从session中获取数据
<input th:value="${session.value1}" />
- JSON在各种语言中的运用
1. JSON数据格式 JSON(JavaScript Object Notation) 从结构上看,所有的数据最终都可以分成三种类型: 第一种类型是scalar(标量),也就是一个单独的strin ...
- JdbcTemplate实现CRUD操作
------------------siwuxie095 JdbcTemplate 实现 CRUD 操作 1.J ...
- Hammer.js——给bootstrap添加触屏功能
Hammer.js qq群号(html5技术交流):158677025 手机端演示二维码(或直接在手机中输入网址:http://lilinfeng.cncoder.me 浏览效果): 一.前言 移 ...