hdu5437(2015长春网络赛A题)
生活随笔
收集整理的這篇文章主要介紹了
hdu5437(2015长春网络赛A题)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:
有一個party,會有n個人來,每個人都帶著禮物來,禮物有權值,由于屋子的大小有限,所以他會選擇k個時間來開門,在t時間讓p個人進來,接下來有q組詢問,每組詢問有一個數字ni,讓你輸出第ni個進入的人是誰。
?
思路 :
使用優先隊列,自己定義一下優先級就好,因為cin和scanf混用我們TLE一次,這是個教訓。
?
代碼:
?
#include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<cmath> #include<string> #include<vector>using namespace std;const int maxn = 150005;struct PER {string name;int pos;int x;bool operator < (const PER& rhs) const {if (rhs.x != x) {return rhs.x > x;}return rhs.pos < pos;} }node[maxn];struct E {int x, y; }e[maxn];bool cmp(E a, E b) {if(a.x != b.x) {return a.x < b.x;}return a.y < b.y; }priority_queue<PER> q;string ans1[maxn]; char str[1000]; int main() {int t;scanf("%d",&t);while(t--){int n,m,kk;scanf("%d%d%d",&n,&m,&kk);for(int i = 1; i <= n; i++) {scanf("%s%d",str,&node[i].x);node[i].name = str;node[i].pos = i;}for(int i = 1; i <= m; i++) {scanf("%d %d",&e[i].x, &e[i].y);}sort(e + 1, e + m + 1,cmp);while(!q.empty()) q.pop();int j = 1;int l = 1;for(int i = 1; i <= m; i++) {while(j <= e[i].x) {q.push(node[j]);j++;}//printf("%d %d\n", e[i].x, e[i].y);for(int k = 1; k <= e[i].y;k++) {if(q.empty()) break;PER p1 = q.top(); q.pop();ans1[l++] = p1.name;// cout << p1.name << " " << p1.x << endl;}}while(j <= n) {q.push(node[j]);j++;}while(!q.empty()) {PER p1 = q.top(); q.pop();ans1[l++] = p1.name;}for(int i = 1; i <= kk; i++) {int xx;scanf("%d",&xx);if(i == 1) printf("%s", ans1[xx].c_str());else printf(" %s", ans1[xx].c_str());}puts("");}return 0; }?
?
?
?
?
總結
以上是生活随笔為你收集整理的hdu5437(2015长春网络赛A题)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++三大继承构造函数的执行顺序详解
- 下一篇: hdu5438(2015长春网络赛B题)