find your present (2) hdoj 2095
2024-08-26 08:51:53
/*
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;
}
}
}
}
最新文章
- 剑指Offer面试题:15.反转链表
- java高新技术-可变参数与OverLoad相关面试题分析
- f
- Charles V4系列更新 | 绿色特别版 | 视频教程
- AndroidStudio调试APP
- 【LeetCode】168 &; 171- Excel Sheet Column Title &; Excel Sheet Column Number
- [LeetCode] Two Sum水过
- 关于C51内的code,idata,xdata
- Deme_遥感控制物体移动(涉及遮罩,小摄像机跟随)
- Android MVC框架模式
- SQL练习1关于插入删除,修改,单表查询
- 3_使用指针对象(Using Object Pointer)
- Angular记录(5)
- SpringBoot集成监控管理
- [转载] About Career Promotion and Tutoring from Zhihu Web FAQer (Quoted Entirely Without Personal Idea. Delete Immediately If Pirated)
- Vue2.5开发去哪儿网App 第五章笔记 下
- Angular中ui-select的使用
- 解问 lambda表达式
- 歌手右侧快速入口ABCD....
- Hyper-V如何新建虚拟机
热门文章
- Excel阅读模式/单元格行列指示/聚光灯开发 技术要点再分享
- MySQL-悲观锁和乐观锁
- pytorch识别CIFAR10:训练ResNet-34(数据增强,准确率提升到92.6%)
- hdu4843(NOI2000) 古城之谜 (trie树+DP)
- Leetcode 8 Two Pointers
- ubuntu下面配置apache
- BZOJ2339[HNOI2011]卡农——递推+组合数
- Android Connection refused
- 我的python之路
- 升级 pip 超时解决方案