山东省第一届ACM大学生程序设计竞赛(原题) Ivan comes again!
2016-04-04 18:03
537 查看
Ivan comes again!
Time Limit: 1000MS Memory limit: 65536K
题目描述
The Fairy Ivan gave Saya three problems to solve (Problem F). After Saya finished the first problem (Problem H), here comes the second.This is the enhanced version of Problem H.
There is a large matrix whose row and column are less than or equal to 1000000000. And there are three operations for the matrix:
1)add: Mark an element in the matrix. The element wasn’t marked before it is marked.
2)remove: Delete an element’s mark. The element
was marked before the element’s mark is deleted.
3)find: Show an element’s row and column,
and return a marked element’s row and column, where the marked element’s row and column are larger than the showed element’s row and column respectively. If there are multiple solutions, return the element whose row is the smallest; and if there are still
multiple solutions, return the element whose column is the smallest. If there is no solution, return -1.
Of course, Saya comes to you for help again.
输入
The input consists of several test cases.The first line of input in each test case contains one integer
N (0<N≤200000), which represents the number of operations.
Each of the next
N lines containing an operation, as described above.
The last case is followed by a line containing one zero.
输出
For each case, print the case number (1, 2 …) first. Then, for each “find” operation, output the result.Your output format should imitate the sample output. Print a blank line after each test case.
示例输入
4 add 2 3 find 1 2 remove 2 3 find 1 2 0
示例输出
Case 1: 2 3 -1
提示
来源
2010年山东省第一届ACM大学生程序设计竞赛示例程序
有3种操作①往集合种加入一个点
②删除集合中一个点
③查询集合中是否存在大于该点的点有输出没有输出-1
根据set自动排序我们采用set来存点
点有二个元素组成所以使用pair
ACcode:
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define maxn 100
using namespace std;
int main(){
int n,loop=1;
char str[10];
while(~scanf("%d",&n)&&n){
pair<int ,int >my;
set<pair<int ,int> >mm;
printf("Case %d:\n",loop++);
while(n--){
scanf("%s",&str);
scanf("%d%d",&my.first,&my.second);
if(str[0]=='a'){
mm.insert(my);
continue;
}
else if(str[0]=='r'){
mm.erase(my);
continue;
}
else {
set<pair <int,int> >::iterator id=mm.lower_bound(my);
while(id!=mm.end()){
if(id->first>my.first&&id->second>my.second){
printf("%d %d\n",id->first,id->second);
break;
}
id++;
}
if(id==mm.end())printf("-1\n");
}
}
printf("\n");
}
return 0;
}
/*
4
add 2 3
find 1 2
remove 2 3
find 1 2
*/
相关文章推荐
- CodeForces 651B Beautiful Paintings
- CodeForces 651B Beautiful Paintings
- 【读书笔记】Android访问远程数据的步骤(Messenger、AIDL、ContentProvider
- 【ZOJ 1937】 【POJ 2248】 Addition Chains
- Poj 2010 Moo University - Financial Aid【优先队列+神技巧】
- RAII&智能指针
- Light OJ 1223 Testing Mailboxes (DP)
- 10014---Trail ~ CronJobs
- 31.offsetof宏与container_of宏
- HDU 5235 Friends (2015 Multi-University Training Contest 2 搜索+剪枝)
- POJ 2010 Moo University - Financial Aid
- 【BZOJ-2434】阿狸的打字机 AC自动机 + Fail树 + DFS序 + 树状数组
- linker command failed with exit code 1)错误总结
- 70. Climbing Stairs
- 本地socket unix domain socket
- 杭电1022Train Problem I
- A. Dreamoon and Stairs(Codeforces Round #272)
- QPainter 使用注意事项
- 杭电1021Fibonacci Again
- 解决sublimeText3无法安装插件有关问题 - There are no packages available for installation