sdut 2159:Ivan comes again!(第一届山东省省赛原题,STL之set使用)
Ivan comes again!
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
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 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.
输出
示例输入
- 4
- add 2 3
- find 1 2
- remove 2 3
- find 1 2
- 0
示例输出
- Case 1:
- 2 3
- -1
提示
来源
- 【set使用心得】
- begin() 返回指向第一个元素的迭代器
- ps:迭代器可以理解为“指针”,使用的使用和指针一样使用。
- 例如:
- set <int> s; //定义一个集合set
- set <int>::iterator it; //定义一个set<int>的迭代器
- it = s.begin();
- cout<<*it<<endl; //输出迭代器指向的元素的值
- 或者:
- set <pair<int,int>> s;
- set <pair<int,int>>::iterator it; //定义一个迭代器
- it = s.begin();
- cout<<it->first<<' '<<it->second<<endl; //输出迭代器指向的元素的值
- clear() 清除所有元素
- count() 返回某个值元素的个数
- empty() 如果集合为空,返回true(真)
- end() 返回指向最后一个元素之后的迭代器,不是最后一个元素
- equal_range() 返回集合中与给定值相等的上下限的两个迭代器
- ps:某个值的[val)区间的两个值。>=val的第一个值作为下限,>val的第一个值作为上限
- erase() 删除集合中的元素
- ps:删除值为val的元素直接用s.erase(val);或者可以删除迭代器指向那个元素
- find() 返回一个指向被查找到元素的迭代器
- ps:注意返回的是一个迭代器
- get_allocator() 返回集合的分配器
- insert() 在集合中插入元素
- ps:要插入某个元素,直接s.insert(val);即可
- lower_bound() 返回指向大于(或等于)某值的第一个元素的迭代器
- ps:返回>=val的第一个元素的迭代器
- key_comp() 返回一个用于元素间值比较的函数
- max_size() 返回集合能容纳的元素的最大限值
- rbegin() 返回指向集合中最后一个元素的反向迭代器
- rend() 返回指向集合中第一个元素的反向迭代器
- size() 集合中元素的数目
- swap() 交换两个集合变量
- upper_bound() 返回大于某个值元素的迭代器
- ps:返回>val的第一个元素的迭代器
- value_comp() 返回一个用于比较元素间的值的函数
这道题拿来熟悉STL很不错。
- #include <iostream>
- #include <stdio.h>
- #include <set>
- #include <utility>
- using namespace std;
- int main()
- {
- int cnt,n;
- for(cnt=;cin>>n;cnt++){
- if(n==) break;
- getchar();
- int i;
- char str[];
- int a,b;
- set < pair<int,int> > s;
- set < pair<int,int> >::iterator it; //定义迭代器
- cout<<"Case "<<cnt<<':'<<endl;
- for(i=;i<=n;i++){
- cin>>str>>a>>b;
- switch(str[]){
- case 'a':
- s.insert(make_pair(a,b)); //像集合s中插入pair(a,b)
- break;
- case 'r':
- s.erase(make_pair(a,b)); //将集合s中值为pair(a,b)的元素删掉
- break;
- case 'f':
- it = s.upper_bound(make_pair(a,b)); //返回集合中大于pair(a,b)的第一个元素
- for(;it!=s.end();it++) //找到第一个比pair(a,b)大的元素
- if(it->first > a && it->second > b)
- break;
- if(it==s.end())
- cout<<-<<endl;
- else
- cout<<it->first<<' '<<it->second<<endl;
- break;
- default:break;
- }
- }
- cout<<endl;
- }
- return ;
- }
Freecode : www.cnblogs.com/yym2013
sdut 2159:Ivan comes again!(第一届山东省省赛原题,STL之set使用)的更多相关文章
- sdut 2158:Hello World!(第一届山东省省赛原题,水题,穷举)
Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...
- sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)
Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...
- sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)
Clockwise Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...
- sdut 2154:Shopping(第一届山东省省赛原题,水题)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- sdut 2165:Crack Mathmen(第二届山东省省赛原题,数论)
Crack Mathmen Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Since mathmen take securit ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- sdut 2163:Identifiers(第二届山东省省赛原题,水题)
Identifiers Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Identifier is an important c ...
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- sdut 2416:Fruit Ninja II(第三届山东省省赛原题,数学题)
Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...
随机推荐
- 关于图片无缝拼接的学习(PTGui)
一.简介 在用到单反.无人机.手机等拍照工具,需要无缝拼接. 二.下载 官网:http://www.ptgui.com/download.html 其他:http://pan.baidu.com/sh ...
- conn
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- zend studio 10安装+破解+汉化
http://pan.baidu.com/share/link?shareid=1857675714&uk=3325301372 在线安装汉化包:http://309614533.blog.1 ...
- 使用rman备份异机恢复数据库
一.RMAN备份源库注意点: 最好保留rman备份日志 $rman target / log=backup.log RMAN>run { allocate channel t1 type dis ...
- 用sp_lock诊断SQL Sever的死锁问题
找出什么被锁定了 系统的反应迟缓意味着你应该做一些调查了.你的查找最好从测定系统发生锁定的数量和频率开始.如果你的系统环境处理事务性很高的话,这样各个应用程序争夺资源就会很常见,从而引起锁定.解决这些 ...
- Java Persistence with MyBatis 小结3
1 映射器配置文件和映射器接口 在 com.mybatis3.mappers 包中的 StudentMapper.xml 配置文件内,是如何配置 id 为”findStudentById”的 SQL ...
- asp.net mvc部署iis常见问题
1.Q:iis比网上的少很多选项 A:iis没装全,去控制面板里把没勾选的选项勾选 2.Q:发布mvc遇到的HTTP错误 403.14-Forbidden解决办法 A:需要在web.config里添加 ...
- atitit。gui 界面皮肤以及换肤总结 java .net c++
atitit.gui 界面皮肤以及换肤总结 java .net c++ 1. Swing 的皮肤 1 1.1. windows风格 1 1.2. Mac风格 ( liquid 框架) 1 2. 如何给 ...
- 479. Second Max of Array【easy】
Find the second max number in a given array. Notice You can assume the array contains at least two n ...
- 集合运算 蓝桥杯 set容器
题目描述 给出两个整数集合A.B,求出他们的交集.并集以及B在A中的余集. 输入格式 第一行为一个整数n,表示集合A中的元素个数. 第二行有n个互不相同的用空格隔开的整数,表示集合A中的元素. 第三行 ...