Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛)
来源:互联网 发布:java程序员培训中心 编辑:程序博客网 时间:2024/05/22 06:10
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.
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 integerN (0<N≤200000), which represents the number of operations.
Each of the nextN lines containing an operation, as described above.
The last case is followed by a line containing one zero.
The first line of input in each test case contains one integerN (0<N≤200000), which represents the number of operations.
Each of the nextN 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.
示例输入
4add 2 3find 1 2remove 2 3find 1 20
示例输出
Case 1:2 3-1
#include <iostream> #include <stdio.h> #include <set> using namespace std; int main() { pair<int,int>p;//声明元素是pair类型如果pair中的第一个数相同,则按第二个数排序,p是包括两个数的,p.first p.secoond int n;char str[10]; int c=1; while(cin>>n&&n) { cout<<"Case "<<c++<<":"<<endl; set< pair<int,int> >s; //声明一个<set>----s while(n--) { scanf("%s",str); scanf("%d%d",&p.first,&p.second); if(str[0]=='a') s.insert(p);//插入一个元素 else if(str[0]=='r') s.erase(p);//删除 else if(str[0]=='f') { set< pair<int,int> >::iterator it; //定义一个set<int>的迭代器 it=s.lower_bound(p);//找到set中第一个比p大的元素的位置,找不到则为s.end() for(;it!=s.end();it++) { if(it->first>p.first&&it->second>p.second)//都大于才符合题意 { cout<<it->first<<" "<<it->second<<endl; break; } } if(it==s.end())//找不到 cout<<-1<<endl; } } cout<<endl; } return 0; }
0 0
- Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛)
- 2010年山东省第一届ACM大学生程序设计竞赛——Ivan comes again!
- 2010年山东省第一届ACM大学生程序设计竞赛——Ivan comes again!
- 山东省第一届ACM大学生程序设计竞赛(原题) Ivan comes again!
- 山东省第一届ACM省赛 Ivan comes again!
- 2010年山东省第一届ACM大学生程序设计竞赛:shopping
- 2010年山东省第一届ACM大学生程序设计竞赛:Balloons
- SDNU 1143.Ivan comes again!【山东省第一届ACM】【7月21】
- 山东省第一届ACM省赛 I SDUT 2159 Ivan comes again!(STL-set)
- 2010山东省ACM省赛 Ivan comes again(set )
- 2010年山东省第一届ACM大学生程序设计竞赛——Balloons
- Phone Number 2010年山东省第一届ACM大学生程序设计竞赛
- Hello World! 2010年山东省第一届ACM大学生程序设计竞赛
- 2010年山东省第一届ACM大学生程序设计竞赛——Clockwise
- 2010年山东省第一届ACM大学生程序设计竞赛——Emergency
- 2010年山东省第一届ACM大学生程序设计竞赛——Fairy tale
- 2010年山东省第一届ACM大学生程序设计竞赛——Greatest Number
- 2010年山东省第一届ACM大学生程序设计竞赛——Shopping
- 字模软件增加函数注释 加HEX空格 next Serial
- 【Java基础】wait(), notify(), notifyAll()
- #pragma pack(push,1)与#pragma pack(1)的区别
- PHP从零单排(十五)牛刀小试--就业信息周报系统
- 设计模式中的“第三方”— 代理、外观、观察和中介者模式
- Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛)
- 关于paintComponent的小细节(Graphics 类)
- 一步步走向国际乱码大赛-- 恶搞C语言
- 写给那些在技术路上奔跑的人们!!!!!
- tnsnames.ora配置小结
- ( 一)bootstrap学习——初识bootstrap
- mongoose 数据库操作3
- 《从程序员到项目经理》读书笔记(八):程序员加油站 -- 再牛也要合群
- css进阶