sdut 2159 Ivan comes again! C++ STL set

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2159

Ivan comes again!
Time Limit: 1000ms   Memory limit: 65536K

200000 operations:

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.

 

#include <cstdio>
#include <iostream>
#include <set>
using namespace std;

set<pair<int,int> > S;
set<pair<int,int> >::iterator it;

int main()
{
    int n,cases=0,x,y;
    char str[10];
    while(scanf("%d",&n),n)
    {
        S.clear();
        printf("Case %d:\n",++cases);
        while(n--)
        {
            getchar();
            scanf("%s%d%d",str,&x,&y);
            switch(str[0])
            {
            case 'a':
                S.insert(make_pair(x,y));
                break;
            case 'r':
                S.erase(make_pair(x,y));
                break;
            case 'f':
                for(it=S.upper_bound(make_pair(x,y)); it!=S.end(); it++)
                {
                    if(it->first>x&&it->second>y) break;
                }
                if(it==S.end()) puts("-1");
                else printf("%d %d\n",it->first,it->second);
                break;
            }
        }
        puts("");
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/syzhd/p/4473459.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值