[Codeforces Round #101 (Div. 2) C. Queue] STL之vector
来源:互联网 发布:有限元分析软件pfepg 编辑:程序博客网 时间:2024/06/05 23:48
[Codeforces Round #101 (Div. 2) C. Queue] STL之vector
题目链接:[Codeforces Round #101 (Div. 2) C. Queue]
题意描述:有N个人排队,现在告诉你每个人前面有
解题思路:
引用官方题解:
Let’s sort the pairs (namei, ai) by ascending of ai. If there is an index i: 0 ≤ i < n that ai > i, then answer is “-1”. Otherwise the answer exists. We will iterate through the array of sorted pairs from left to right with supporting of vector of results res. Let on the current iteration ai = n - i, then we must transfer the current man in the position ai. It can be done in C++ with one line: res.insert(res.begin() + a[i], man);
#include <bits/stdc++.h>using namespace std;#define FIN freopen("input.txt","r",stdin)#define FOUT freopen("output.txt","w",stdout)#define fst first#define snd secondtypedef __int64 LL;//typedef long long LL;typedef pair<int, int> PII;const int MAXN = 3000 + 5;int N, M, K;char buf[MAXN][15];PII ele[MAXN];vector<PII> res;int main() {#ifndef ONLINE_JUDGE FIN;#endif // ONLINE_JUDGE while (~scanf ("%d", &N) ) { for (int i = 1; i <= N; i++) { scanf ("%s %d", buf[i], &ele[i].fst); ele[i].snd = i; } sort (ele + 1, ele + N + 1); bool suc = true; for (int i = 1; i <= N; i++) { if (ele[i].fst >= i) suc = false; } if (!suc) { printf ("-1\n"); continue; } res.clear(); for (int i = 1, k = N; i <= N; i++, k--) { res.insert (res.begin() + ele[i].fst, make_pair (ele[i].snd, k) ); } for (int i = 0; i < N; i++) { PII& e = res[i]; printf ("%s %d\n", buf[e.fst], e.snd); } } return 0;}
0 0
- [Codeforces Round #101 (Div. 2) C. Queue] STL之vector
- Codeforces Round #304 (Div. 2) C queue暴力
- Codeforces Round #296 (Div. 2) - C. Glass Carving(STL)
- Codeforces Round #344 (Div. 2) 631C Report(脑洞+stl)
- Codeforces Round #279 (Div. 2)B. Queue
- Codeforces Round #279 (Div. 2) B. Queue
- Codeforces Round #398 (Div. 2)The Queue
- Codeforces Round #Pi (Div. 2) (STL专场)
- Codeforces Round #149 (Div. 2) (bfs+STL)
- 【Codeforces Round #398 (Div. 2)】Codeforces 767B The Queue
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #349 (Div. 2) A B C[dp] D[spfa] +vector
- Codeforces Round #355 (Div. 2) A B C D vector + map spfa
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C (dfs+vector)
- Codeforces Round #249 (Div. 2) A. Queue on Bus Stop
- Codeforces Round #249 (Div. 2) A - Queue on Bus Stop
- Codeforces Round #279 (Div. 2), problem: (B) Queue
- Codeforces Round #279 (Div. 2) B. Queue 模拟
- 单线程端口扫描
- Android Java混淆(ProGuard)
- 推荐算法1-content based recommendation
- 永远要设定deadline,完成比完美更重要
- Shell每日闪记1
- [Codeforces Round #101 (Div. 2) C. Queue] STL之vector
- C#入门11.1——捕获异常
- 使用事件驱动模型实现高效稳定的网络服务器程序
- linux指令解析-mount df du fdisk apt-get dd
- hdu 2255 奔小康赚大钱【Kuhn_Munkras】
- 浙大PAT甲级 1092
- [旋转卡壳] BZOJ 1185 [HNOI2007]最小矩形覆盖 && 2218 Uva10173 Smallest Bounding Rectangle
- linux 中 inode 的理解
- Animate.css