HDU 2095(map)
来源:互联网 发布:mysql left out join 编辑:程序博客网 时间:2024/06/15 11:37
这道题刚开始用排序做,结果Memory Limit Exceeded了,发现内存限制在1024k,额,,好吧。。最后看书用map映照容器做的
注意划线部分,不注意很可能会理解错题意!!
find your present (2)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/1024 K (Java/Others)
Total Submission(s): 14705 Accepted Submission(s): 5568
Problem Description
In the new year party, everybody will get a "special present".Now it's your turn to get your special present, a lot of presents now putting on the desk, and only one of them will be yours.Each present has a card number on it, and your present's card number will be the one that different from all the others, and you can assume that only one number appear odd times.For example, there are 5 present, and their card numbers are 1, 2, 3, 2, 1.so your present will be the one with the card number of 3, because 3 is the number that different from all the others.
Input
The input file will consist of several cases.
Each case will be presented by an integer n (1<=n<1000000, and n is odd) at first. Following that, n positive integers will be given in a line, all integers will smaller than 2^31. These numbers indicate the card numbers of the presents.n = 0 ends the input.
Each case will be presented by an integer n (1<=n<1000000, and n is odd) at first. Following that, n positive integers will be given in a line, all integers will smaller than 2^31. These numbers indicate the card numbers of the presents.n = 0 ends the input.
Output
For each case, output an integer in a line, which is the card number of your present.
Sample Input
51 1 3 2 231 2 10
Sample Output
32use scanf to avoid Time Limit ExceededHintHint
程序如下:
#include<map>#include<cstdio>using namespace std;int main(){ int t,n,i; while(~scanf("%d",&t),t) { map<int,int> m; for(i=0; i<t; i++) { scanf("%d",&n); m[n]++; //计算每个数字出现的次数 } map<int,int>::iterator it; for(it=m.begin(); it!=m.end(); it++) { if((*it).second == 1) //如果次数出现1的就是它了 { printf("%d\n",(*it).first); break; } } } return 0;}
后来发现有人用异或做出来了,真是叼炸天了。。
程序如下:
//异或^运算符使用规则://先转换为二进制,然后:遵循a^a=0,a^0=a规则#include <stdio.h>int main(){int n,s,a;while(~scanf("%d",&n),n) {s = 0;while(n--){scanf("%d",&a);s ^= a;}printf("%d\n",s);}return 0;}//如果多次进行^运算,那么出现偶数次的相同的数就会抵消为0,奇数次的数则会保留一个下来//如果还不懂可以自己举个例子,比如①^②^③(代表3个不同的十进制数)如下图://当然奇数次的数只能有一个才能出现正确结果,由于题目是输出奇数次的数,所以可行
0 0
- HDU 2095(map)
- hdu 2095 map水
- hdu 1004(map)
- hdu 1217 map+floyd
- hdu 1029 map做法
- HDU 1048 map
- hdu - 4329 - MAP - 模拟
- hdu 1004 hash map
- hdu 1004 (map)
- hdu 1075 map
- map 初学 hdu 1800
- HDU 4302 MAP应用
- HDU 2112 Map+Dijkstra
- hdu-1800(map)
- HDU 1307 map&&set
- hdu 1381 map(映射)
- HDU 1327 map
- 【map】【multiset】hdu 4022
- Vim在windows下屏蔽系统自带的 .vimrc
- 输入整数,偶数偶数,从高位到低位的顺序组成一个新的数
- CListCtrl自绘
- jbpm4.4下hibernate映射文件中表跟类的对应关系
- 网络爬虫
- HDU 2095(map)
- 范数规则化
- 仿path菜单的实现原理,例ArcMenu
- OpenCL: 解决图像半透明算法
- cut、tee、split、xargs、bc命令
- Ubuntu安装配置NFS文件系统
- cocos2d 竖屏
- spring mvc 与struts2区别
- 网络金融让银行出一身冷汗