码迷,mamicode.com
首页 > 其他好文 > 详细

SDNU 1143.Ivan comes again!【山东省第一届ACM】【7月21】

时间:2015-07-22 00:12:04      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:sdnu   山东第一届acm   acm   

Ivan comes again!

Description

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.

Input

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.

Output

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.

Sample Input

4
add 2 3
find 1 2
remove 2 3
find 1 2

0

Sample Output

Case 1:
2 3
-1
继续省赛题。题目大意:
add:添加该点
find:找横纵坐标都大于该点的最小的点
remove:删除该点
模拟就好~~用set<pair<int,int> >存。代码贴上:
#include<cstdio>
#include<string>
#include<set>;
using namespace std;
pair<int,int>pai;//放在set里
int main(){
    int n,kase=0;
    while(scanf("%d",&n)==1&&n){
        printf("Case %d:\n",++kase);
        set<pair<int,int> >f;
        char x[7];
        while(n--){
            scanf("%s",x);
            scanf("%d%d",&pai.first,&pai.second);
            if(x[0]=='a')
                f.insert(pai);
            else if(x[0]=='r')
                f.erase(pai);
            else{//这是难点
                set<pair<int,int> >::iterator it=f.lower_bound(pai);//lower_bound()返回指向大于(或等于)某值的第一个元素的迭代器
                for(;it!=f.end();it++){
                    if(it->first>pai.first&&it->second>pai.second){
                        printf("%d %d\n",it->first,it->second);
                        break;//这么重要的语句竟然忘了!!!!!找到一个点就可以退出来了····
                    }
                }
                if(it==f.end())
                    printf("-1\n");
            }
        }
    printf("\n");
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

SDNU 1143.Ivan comes again!【山东省第一届ACM】【7月21】

标签:sdnu   山东第一届acm   acm   

原文地址:http://blog.csdn.net/a995549572/article/details/46991881

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!