HDU 5071 Chat (模拟)
来源:互联网 发布:淘宝上战地1那家店好 编辑:程序博客网 时间:2024/06/07 04:57
题意:
题意还是很明确的, 就是最后一段要仔细读
分析:
需要的注意的就是top操作不是真的放到队列首, 只是一个标记, 最后Bye的时候要先给top的, 然后没有的话, 就从头开始Bye
写法就vector,map暴力就好了,需要注意的时候Close的时候别忘记删掉map里的
模拟赛的时候1Y这个模拟真是太激动人心了
代码:
//// Created by TaoSama on 2015-10-10// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;int n;vector<int> v;map<int, int> mp;int main() {#ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);#endif ios_base::sync_with_stdio(0);// vector<int> vv; vv.push_back(1); vv.push_back(2);// vv.insert(vv.begin(), 3);// for(auto v : vv) printf("%d ", v); puts(""); int t; scanf("%d", &t); while(t--) { scanf("%d", &n); char op[10]; int x, top = -1; v.clear(); mp.clear(); for(int i = 1; i <= n; ++i) { scanf("%s", op); printf("Operation #%d: ", i); if(!strcmp(op, "Add")) { scanf("%d", &x); if(mp.count(x)) puts("same priority."); else { v.push_back(x); mp[x] = 0; puts("success."); } } else if(!strcmp(op, "Close")) { scanf("%d", &x); if(!mp.count(x)) puts("invalid priority."); else { v.erase(find(v.begin(), v.end(), x)); printf("close %d with %d.\n", x, mp[x]); mp.erase(x); } } else if(!strcmp(op, "Chat")) { scanf("%d", &x); if(!v.size()) puts("empty."); else { if(~top) mp[top] += x; else mp[v[0]] += x; puts("success."); } } else if(!strcmp(op, "Rotate")) { scanf("%d", &x); if(x < 0 || x > v.size()) puts("out of range."); else { int tmp = v[x - 1]; v.erase(v.begin() + x - 1); v.insert(v.begin(), tmp); puts("success."); } } else if(!strcmp(op, "Prior")) { if(!v.size()) puts("empty."); else { int idx = 0; for(int k = 0; k < v.size(); ++k) if(v[k] > v[idx]) idx = k; int tmp = v[idx]; v.erase(v.begin() + idx); v.insert(v.begin(), tmp); puts("success."); } } else if(!strcmp(op, "Choose")) { scanf("%d", &x); if(!mp.count(x)) puts("invalid priority."); else { v.erase(find(v.begin(), v.end(), x)); v.insert(v.begin(), x); puts("success."); } } else if(!strcmp(op, "Top")) { scanf("%d", &x); if(!mp.count(x)) puts("invalid priority."); else { top = x; puts("success."); } } else { if(~top) { top = -1; puts("success."); } else puts("no such person."); } } int tmp; if(~top) { tmp = mp[top]; if(tmp) printf("Bye %d: %d\n", top, tmp); } for(int k = 0; k < v.size(); ++k) { if(v[k] == top) continue; tmp = mp[v[k]]; if(tmp) printf("Bye %d: %d\n", v[k], tmp); } } return 0;}
0 0
- hdu 5071 Chat(模拟)
- HDU 5071 Chat (模拟)
- HDU 5071 Chat(模拟)
- hdu 5071 Chat(模拟)
- HDU 5071 Chat (模拟)
- hdu 5071 Chat(大模拟)
- hdu 5071 Chat (模拟题)
- hdu 5071 Chat(模拟|Splay)
- HDU 5071 Chat 暴力模拟
- HDU 5071 Chat(大模拟)
- HDU -- 5071 Chat 超强模拟
- HDU 5071 Chat (神一般的模拟题)
- HDU 5071 Chat(2014鞍山B,模拟)
- 【模拟】 HDOJ 5071 Chat
- HDOJ 5071 Chat 模拟
- hdu 5071 Chat /2014鞍山现场赛B题 (模拟)
- HDU 5071 Chat
- hdu 5071 Chat
- POJ 1661 Help Jimmy (DP)
- 可多选的图片选择框
- 第一阶段考核中的JAVA简答题
- H264 Format 方式
- 用GUI实现求两个数的加法--方法一
- HDU 5071 Chat (模拟)
- 最长公共子序列
- 用GUI实现求两个数的加法--方法二
- Android如何获取当前手机的网络状态
- SQL Server 2005的安装
- fmt:formatDate格式化时间
- 数据结构实习二1
- hdu 2204 Eddy's爱好(容斥原理)
- BCRound #59 (div.2)