uvalive 3135 Argus

解题思路:STL —— priority_queue

  1 ///////////////////////////////////////////////////////////////////////////
  2 //problem_id: uvalive 3135
  3 //user_id: SCNU20102200088
  4 ///////////////////////////////////////////////////////////////////////////
  5 
  6 #include <algorithm>
  7 #include <iostream>
  8 #include <iterator>
  9 #include <iomanip>
 10 #include <cstring>
 11 #include <cstdlib>
 12 #include <string>
 13 #include <vector>
 14 #include <cstdio>
 15 #include <cctype>
 16 #include <cmath>
 17 #include <queue>
 18 #include <stack>
 19 #include <list>
 20 #include <set>
 21 #include <map>
 22 using namespace std;
 23 
 24 ///////////////////////////////////////////////////////////////////////////
 25 #pragma comment(linker,"/STACK:1024000000,1024000000")
 26 
 27 #define lson l,m,rt<<1
 28 #define rson m+1,r,rt<<1|1
 29 ///////////////////////////////////////////////////////////////////////////
 30 
 31 ///////////////////////////////////////////////////////////////////////////
 32 const double EPS=1e-9;
 33 const double PI=acos(-1.0);
 34 const double E=2.7182818284590452353602874713526;
 35 
 36 const int x4[]={-1,0,1,0};
 37 const int y4[]={0,1,0,-1};
 38 const int x8[]={-1,-1,0,1,1,1,0,-1};
 39 const int y8[]={0,1,1,1,0,-1,-1,-1};
 40 ///////////////////////////////////////////////////////////////////////////
 41 
 42 ///////////////////////////////////////////////////////////////////////////
 43 typedef long long LL;
 44 
 45 typedef int T;
 46 T max(T a,T b){ return a>b? a:b; }
 47 T min(T a,T b){ return a<b? a:b; }
 48 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
 49 T lcm(T a,T b){ return a/gcd(a,b)*b; }
 50 ///////////////////////////////////////////////////////////////////////////
 51 
 52 ///////////////////////////////////////////////////////////////////////////
 53 //Add Code:
 54 struct Node{
 55     int x,y,z;
 56     bool operator <(const Node &a) const{
 57         if(y==a.y) return x>a.x;
 58         return y>a.y;
 59     }
 60 };
 61 
 62 priority_queue<Node> pq;
 63 ///////////////////////////////////////////////////////////////////////////
 64 
 65 int main(){
 66     ///////////////////////////////////////////////////////////////////////
 67     //Add Code:
 68     int a,b,k;
 69     char c[10];
 70     while(scanf("%s",c)!=EOF){
 71         if(c[0]=='#') break;
 72         scanf("%d%d",&a,&b);
 73         Node res=Node{a,b,b};
 74         pq.push(res);
 75     }
 76     scanf("%d",&k);
 77     while(k--){
 78         Node now=pq.top();
 79         pq.pop();
 80         printf("%d\n",now.x);
 81         Node res=Node{now.x,now.y+now.z,now.z};
 82         pq.push(res);
 83     }
 84     ///////////////////////////////////////////////////////////////////////
 85     return 0;
 86 }
 87 
 88 ///////////////////////////////////////////////////////////////////////////
 89 /*
 90 Testcase:
 91 Input:
 92 Register 2004 200
 93 Register 2005 300
 94 #
 95 5
 96 Output:
 97 2004
 98 2005
 99 2004
100 2004
101 2005
102 */
103 ///////////////////////////////////////////////////////////////////////////

posted on 2013-09-17 16:19  SCNU20102200088  阅读(224)  评论(0编辑  收藏  举报

导航