CodeForces 705C 我被set.erase(*it)套路了
来源:互联网 发布:买房贷款利息怎么算法 编辑:程序博客网 时间:2024/04/19 13:53
深夜写题解,我只想说内心是崩溃的。
题意:三种操作1.某APP来一个消息 2.读完APPx的所有消息 3.读完前t个消息(是前t个,包括读过的)
想法:静下心读懂题意,想好思路再做算法设计要有明确的伪代码,才能保证万无一失
set.erase(*it); 删除*it的值之后,你会发现如果你用的是for(it = st.begin(); it != st.end(); it++) ,你会发现删除一个之后会出现数据错乱!因为st.begin()的位置变了,注意~~~~!!!!!
http://codeforces.com/contest/705/problem/C
题解:
#include <bits/stdc++.h>using namespace std;typedef pair<string, string> P;typedef long long LL;#define INF 0x3f3f3f3f#define PI acos(-1)#define MAX_N 300005#define LOCALset<int> st; //all indexqueue<int> que[MAX_N];int cnt = 0;void solve(int type, int xt){ if(type == 1) { cnt++; //the index que[xt].push(cnt); st.insert(cnt); } else if(type == 2) { while(!que[xt].empty()) { st.erase(que[xt].front()); que[xt].pop(); } } else if(type == 3) { set<int>::iterator it; int cntnow = 0; for(it = st.begin(); it!=st.end(); it++) //你妈神坑~~~ 记得你st.erase()后再st.begin()就变了 { cout << *it << " " ; if(*it <= xt) st.erase(*it); else break; } cout << endl; }}int main(){#ifdef LOCALfreopen("b:\\data.in.txt", "r", stdin);#endifint n, q; scanf("%d%d", &n, &q); for(int i = 0; i < q; i++) { int type, xt ; scanf("%d%d", &type, &xt); solve(type, xt);// printf("%d\n", st.size()); } return 0;}
0 0
- CodeForces 705C 我被set.erase(*it)套路了
- set:: erase
- set容器的erase
- Codeforces 468C Hack it!
- 我的IT起步了
- 你好,IT我来了!
- STL_set——set::erase
- C++/STL用erase删除元素(vector,deque),(list,set,map)
- CodeForces 275C k-Multiple Free Set
- Codeforces 497C Distributing Parts set+贪心
- Codeforces 527C Glass Carving(Set)
- Codeforces 527C Glass Carving (set+multiset)
- CodeForces 527C(set大法好)
- Codeforces 527C 线段树 /set
- Codeforces 667C Reberland Linguistics dp+set
- CodeForces - 722C Destroying Array (set)
- CodeForces 831C Jury Marks(set)
- Codeforces 527C Glass Carving (set+multiset)
- 【NOI2010T1】能量采集-容斥原理
- C++11 多线程中的call once
- VHDL2
- Log4Net日志记录两种方式
- autoit3中有关Send的用法
- CodeForces 705C 我被set.erase(*it)套路了
- Android事件分发流程
- 【JVM】内存区
- [精] C++11中once_flag,call_once实现分析
- 查询表结构的SQL语句
- android之R cannot be resolved to a variable
- centos6.5 make编译依赖关系的文件
- 互联网公司的技术体系
- 在两个不同环境下的composer的安装