Yuna's confusion
来源:互联网 发布:医学影像专业英语软件 编辑:程序博客网 时间:2024/06/04 18:08
Problem Description
After yuna studies the STL container,she finds the STL powerful for AC.For the k-th number, she is also very familiar with it. Now yuna meets a very similar problem, yuna wants to design a container, the container is to support the three operations,including add,del and query.
Although yuna is very intelligent, she can not think of how to do it, can you help her to solve this problem?
Although yuna is very intelligent, she can not think of how to do it, can you help her to solve this problem?
Input
Input contains multiple test cases.,Each test case the first number is an integer n (1 <= n <100000), means that the number of operation to do. The next m lines, each line will be an string at the beginning, s which has three values:
If s is “Add”, then there will be an integer i (0 <i <100000), means press element i into Container.
If s is “Del”, then there will be an integer i (0 <i <100000), indicated that delete the element i from the container
If s is “Query”, then there will be two integers x and k (0 <x <100000, 0 <k <10000),means the inquiries, the element is greater than x, and the k-th larger number.
If s is “Add”, then there will be an integer i (0 <i <100000), means press element i into Container.
If s is “Del”, then there will be an integer i (0 <i <100000), indicated that delete the element i from the container
If s is “Query”, then there will be two integers x and k (0 <x <100000, 0 <k <10000),means the inquiries, the element is greater than x, and the k-th larger number.
Output
For each deletion, if you want to delete the element which does not exist, the output "No Elment!". For each query, output the suitable answers in line .if the number does not exist, the output "Not Find!".
Sample Input
5Add 5Del 2Add 6Query 3 2Query 8 17Add 2Add 2Add 4Query 1 1Query 1 2Query 1 3Query 1 45Add 5Add 5Del 5Del 5Query 1 1
Sample Output
No Elment!6Not Find!224Not Find!Not Find!
Author
Source
developing schools contest 5
传说中的水题,正解是用线段树做的,不过用简单的STL水过了.......
谁说vector不可以排序,只要用的好一样能排
#include <iostream>#include <vector>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;vector<int> v;int main(){ int n; char job[20]; int x; int y; while(scanf("%d%*c",&n)!=EOF) { v.clear(); while(n--) { vector<int>::iterator it; scanf("%s",job); if(strcmp(job,"Add")==0) { scanf("%d%*c",&x); it=upper_bound(v.begin(),v.end(),x);//这个地方对vector进行排序,因为每次插入的时候是不会影响原来的顺序所以,插入之后还是有序的 v.insert(it,x); } else if(strcmp(job,"Del")==0) { scanf("%d%*c",&x); it=find(v.begin(),v.end(),x); if(it==v.end()) { printf("No Elment!\n"); } else { v.erase(it);//这个地方删除的是一个元素,并不是所有的元素 } } else { scanf("%d%d",&x,&y); it=upper_bound(v.begin(),v.end(),x); if(it==v.end()) { printf("Not Find!\n"); } else { it+=(y-1); if(it>=v.end()) { printf("Not Find!\n"); } else printf("%d\n",*it); } } } } return 0;}
- Yuna's confusion
- Confusion
- confusion
- Cocos2d-x MultipleTouch & CCControllButton's confusion
- HLG 1251 Marshal's Confusion III
- HLG 1251 Marshal's Confusion III (快速幂)
- Hust oj 1196 Marshal's confusion II(公式)
- HRBUST 1251 Marshal's Confusion III 【快速幂】 (2013 3.13)
- 哈理工 1251 Marshal's Confusion III(太坑快速幂)
- Hust oj 1521 Marshal's Confusion III(整数快速幂)
- 哈理工OJ 1196 Marshal's confusion II(数学公式题)
- Confusion Matrix
- Confusion Matrix
- Confusion Matrix
- Confusion Matrix
- A.yuna学数论(解题报告)
- linux grub confusion
- Confusion, diffusion, Collision, Substitution
- 常用网站记录
- UINavagationBar设置背景图片,最简单的方法
- 用图示的方式来讲解下PhoneGap
- Qt中设置对话框的属性
- 你必须非常努力,才能看起来毫不费力
- Yuna's confusion
- 我的"私有云"——在Ubuntu 12.04 LTS上部署ownCloud4
- 我的QQ密保卡,不许偷看哦
- 8月13日记录
- HDU 4351 - Digital root
- 通过例子学反射
- oracle 强制删除用户session
- 服务端的未来属于Node.js
- Spindle:让你在逛街时抓住每一个促销活动