Codeforces 799B
来源:互联网 发布:深圳代理注册公司 知乎 编辑:程序博客网 时间:2024/06/05 11:57
cf 一般都在晚上,这一场没做,听同学说这个题很迷,来了兴趣,就做了一下
开始想用set ,但感觉好恶心的,不易实现,细思之下想到了好的办法,算是 “贪心” 了一下
运用 queue 先进先出 结合 结构体,嗯,不错
这种顺序问题,最好寻找一种规律,想到了 会很简单;整个代码我也就敲了20分钟吧,前面思考的过程耗时间
#include<iostream>#include<algorithm>#include<cstdio>#include<set>#include<queue>using namespace std;const int maxn = 200000 + 50;int n, m;queue<int> q1;queue<int> q2;queue<int> q3;struct node { int pr; int f; int x; int y;};node a[maxn];bool cmp(node a, node b) { return a.pr < b.pr;}void clear_() { while(!q1.empty()) q1.pop(); while(!q2.empty()) q2.pop(); while(!q3.empty()) q3.pop();}void init() { clear_(); scanf("%d", &n); for(int i = 0; i < n; ++i) { scanf("%d", &a[i].pr); a[i].f = 1; } for(int i = 0; i < n; ++i) scanf("%d", &a[i].x); for(int i = 0; i < n; ++i) scanf("%d", &a[i].y); sort(a, a+n, cmp); for(int i = 0; i < n; ++i) { if(a[i].x == 1 || a[i].y == 1) q1.push(i); if(a[i].x == 2 || a[i].y == 2) q2.push(i); if(a[i].x == 3 || a[i].y == 3) q3.push(i); }}void solve(){ scanf("%d", &m); for(int i = 0; i < m; ++i) { int ff = 0, b; scanf("%d", &b); if(i) cout << " "; if(b == 1) { while(!q1.empty()) { int t = q1.front(); if(a[t].f) { a[t].f = 0; cout << a[t].pr; ff = 1; } q1.pop(); if(ff) break; } if(!ff) cout << -1; } else if(b == 2) { while(!q2.empty()) { int t = q2.front(); if(a[t].f) { a[t].f = 0; cout << a[t].pr; ff = 1; //cout << "==" << } q2.pop(); if(ff) break; } if(!ff) cout << -1; } else if(b == 3) { while(!q3.empty()) { int t = q3.front(); if(a[t].f) { a[t].f = 0; cout << a[t].pr; ff = 1; } q3.pop(); if(ff) break; } if(!ff) cout << -1; } } //cout << endl;}int main() { init(); solve(); return 0;}
1 0
- Codeforces 799B
- Codeforces 799B
- [CodeForces-799B]
- CodeForces 799B (B) T-shirt buying
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- Codeforces 799B T-shirt buying 题解
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- CentOS 6.x 启动流程
- 5月15日
- 台灯
- 剑指offer 14. 调整数组顺序使奇数位于偶数前面
- Gradle教程--基础篇
- Codeforces 799B
- springcloud(二):注册中心Eureka
- 根据输入选项shell脚本添加信息
- iOS AFNetWorking与线程同步
- 开源 java CMS
- 二维数组的遍历
- Mac显示隐藏文件方法
- Ubuntu 16.04 安装 tweak 及 Flatabulous 主题美化
- redis desktop manager 连不上