ZOJ 3633 Alice's present
来源:互联网 发布:三国杀风火山林淘宝 编辑:程序博客网 时间:2024/05/16 13:54
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3633
这个应该算是ZOJ的水题了吧!只可惜比赛的时候虽然想到了用STL里的map,但是因为对map不熟悉所以没用map搞,于是比赛的时候没有A掉这道题。有时间要学习整理一下STL一些常用的东西了。
题意:Alice将她的娃娃排成了一排,她要选一段(连续的)娃娃作为礼物送给Marisa,她不希望这些娃娃里有重复的,所以要变一个程序检查是否有重复的,如果没有则输出“OK”,否则输出最先出现重复的娃娃编号。
思路:用STL的map的find()判断是否有重复。
#include<cstdio>#include<map>using namespace std;int num[555555];map <int,int> mp;int main(){int n,m,u,v;while(scanf("%d",&n)==1){int i;for(i=1;i<=n;i++){scanf("%d",&num[i]);}scanf("%d",&m);while(m--){ scanf("%d %d",&u,&v);mp.clear();for(i=v;i>=u;i--){ if(!mp.count(num[i]))//count()用来查找元素num[i],如果找到返回1,如果没找到则返回0; //if(mp.end()==mp.find(num[i]))//find()用来查找元素num[i],如果找到返回指向该元素的迭代器,如果没找到则返回指向map末尾的迭代器;end()返回指向map末尾的迭代器。 mp[num[i]]=1; else break;}if(i<u) printf("OK\n"); else printf("%d\n",num[i]);}printf("\n");}return 0;}
- ZOJ 3633 Alice's present
- ZOJ-3633-Alice's present
- zoj 3633 Alice's present
- Zoj 3633 Alice's present
- zoj 3633 Alice's present
- ZOJ 3633 Alice's present
- ZOJ 3633Alice's present
- zoj 3633 Alice's present
- zoj 3633 Alice's present
- ZOJ-3633-Alice's present
- zoj 3633 Alice's present 线段树
- zoj(3633)Alice‘s present
- ZOJ 3633 Alice's present【线段树】
- ZOJ 3633Alice's present (脑洞题)
- ZOJ 3633 Alice's present (STL set)
- zoj 3633 Alice's present(离线+线段树)
- zoj-3633 Alice's present 离线线段树
- [ZOJ 3633]Alice's present 离线分块/线段树
- Ubuntu下Jenkins 安装
- Huffman编码树
- java位运算
- Android4.0 设置系统默认输入法
- 在虚拟机vmware8.0上安装mac os lion 10.7和xcode4.1
- ZOJ 3633 Alice's present
- 云计算技术
- Informix数据库驱动连接问题
- Huffman树结构的实现(上)
- UIImage 图片处理:截图,缩放,设定大小,存储
- Jamendo学习之缓存:RequestCache、ImageCache
- 移植Linux-2.6.30.4到mini2440
- 中国程序员
- Huffman树结构的实现(下)