FZU 2029 买票问题
2013-11-03 09:50
218 查看
好久没有做题了,开始做这道题时也不知道是咋想的,竟然有链表去实现,弄了好大时候也没弄出来,最后网上看了一下思路,
豁然开朗,用数组就可以实现,总体来说这题用的知识有map<int,int>映射:把输入的x映射为1,2,3...;还有就是树状数组
求"check x y"的值,再加上一个flag数组标记x是否在队列里边就OK了!具体看代码实现吧…………
豁然开朗,用数组就可以实现,总体来说这题用的知识有map<int,int>映射:把输入的x映射为1,2,3...;还有就是树状数组
求"check x y"的值,再加上一个flag数组标记x是否在队列里边就OK了!具体看代码实现吧…………
#include <iostream> #include <vector> #include <queue> #include <map> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; #define N 100005 int n, a , num, top; struct node{ int x, y; node(int x, int y):x(x), y(y){} node(){} }; bool operator < (node a, node b){ return a.y > b.y; } int lowbit(int x){ return x & (-x); } void update(int x, int v){ while( x <= n ){ a[x] += v; x += lowbit(x); } } int sum(int x){ int ans = 0; while( x > 0 ){ ans += a[x]; x -= lowbit(x); } return ans; } int main() { int t, x, y; char ss[8]; while(~scanf("%d", &t)){ n = t; top = 0, num = 1; map<int, int> m; bool flag ; priority_queue<node> q; memset(a, 0, sizeof(a)); memset(flag, false, sizeof(flag)); while(t--){ scanf("%s", ss); if(ss[0] == 'l') { while( !q.empty() && !flag[q.top().x] ) q.pop(); if( !q.empty() ) { int k = q.top().x; q.pop(); flag[ k ] = false; update(k, -1); } } else if(ss[0] == 'p') { while( top < num && !flag[top] ) top++; if( top + 1 > num ) continue; update( top, -1 ); flag[top] = false; top++; } else if( ss[0] == 'a' ){ scanf("%d%d", &x, &y); q.push(node(num, y)); flag[ m[x] = num ] = true; num++; } else { scanf("%d%d", &x, &y); x = m[x]; if( !flag[x] ) continue; int yy = x + sum(x-1) - 1; printf("%d\n", yy); if( yy > y ){ update( x, -1 ); flag[x] = false; } } } } return 0; }
相关文章推荐
- FZU 2029 买票问题 树状数组+STL
- 树状数组+STL FZU 2029 买票问题
- FZU 1205 小鼠迷宫问题 <BFS+DFS>
- FZU数据结构精品课程 2.1 选举问题
- FZU 1686 神龙的难题(重复覆盖问题)
- 巧妙的实现多个进程同时跑的问题~买票系统
- FZU 2031 计数问题
- 黄牛是怎样抢票的?——从业务分析师角度看买票难问题
- FZU1205 之 小鼠迷宫问题
- [中国邮路问题 欧拉回路 最短路 一般图匹配||状压DP] FZU 1009 Jogging Trails
- FZU 1062 洗牌问题(打表找规律)
- 买票问题
- FZU 1895 整除45问题
- FZU 1062 洗牌问题
- 从《编程之美》买票找零问题说起,娓娓道来卡特兰数——兼爬坑指南
- FZU 1062 洗牌问题(打表找规律)
- 【小白的java成长系列】——多线程初识(多人买票问题)
- 买票感悟——全面的去看待问题
- FZU 2028 时空门问题(bfs+vector)
- FZU 2027 - 单词问题