题目:https://icpcarchive.ecs.baylor.edu/external/31/3135.pdf
第一种写法,比下面的快多了:
const int INF =0x3f3f3f3f;
const int maxn= 3010 ;
//const int maxm= ;
//by yskysker123
char s[20];
struct OP
{
int num;
int time;
int index;
OP(){}
OP(int &num,int time,int index):num(num),time(time),index(index){}
} op[maxn];
struct cmp
{
bool operator ()(OP x,OP y)const
{
if(y.time!=x.time)
return x.time>y.time;
return x.num>y.num;
}
};
priority_queue<OP ,vector<OP> ,cmp > q;
int main()
{
while(!q.empty() ) q.pop();
int cnt=0,k;
while(~scanf("%s",s)&&strcmp(s,"#")!=0)
{
cnt++;
scanf("%d",&op[cnt].num);
scanf("%d",&op[cnt].time);
op[cnt].index=cnt;
q.push(op[cnt] );
}
scanf("%d",&k);
for(int i=1;i<=k;i++)
{
OP tmp=q.top(); q.pop();
int num=tmp.num;
int time=tmp.time;
int index=tmp.index;
q.push(OP( num,time+ op[index].time,index ));
printf("%d\n",num);
}
return 0;
}
这个比前面慢几倍,如果数据大我认为是会超时的。
const int INF =0x3f3f3f3f;
const int maxn= 3010 ;
//const int maxm= ;
//by yskysker123
char s[20];
struct OP
{
int num;
int time;
OP(){}
OP(int &num,int time):num(num),time(time){}
} op[maxn];
struct cmp
{
bool operator ()(OP x,OP y)const
{
if(y.time!=x.time)
return x.time>y.time;
return x.num>y.num;
}
};
priority_queue<OP ,vector<OP> ,cmp > q;
int main()
{
while(!q.empty() ) q.pop();
int cnt=0,k;
while(~scanf("%s",s)&&strcmp(s,"#")!=0)
{
cnt++;
scanf("%d",&op[cnt].num);
scanf("%d",&op[cnt].time);
}
scanf("%d",&k);
for(int now=1;now<=cnt;now++)
{
int num=op[now].num;
int time=op[now].time;
for(int i=1;i<=k;i++)
{
q.push(OP(num,time*i) ); //前一次竟然写成了 k*time ;
}
}
for(int i=1;i<=k;i++)
{
int num=q.top().num; q.pop();
printf("%d\n",num);
}
return 0;
}
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<climits>
#include<queue>
#include<vector>
#include<map>
#include<sstream>
#include<set>
#include<stack>
#include<utility>
#pragma comment(linker, "/STACK:102400000,102400000")
#define PI 3.1415926535897932384626
#define eps 1e-10
#define sqr(x) ((x)*(x))
#define FOR0(i,n) for(int i=0 ;i<(n) ;i++)
#define FOR1(i,n) for(int i=1 ;i<=(n) ;i++)
#define FORD(i,n) for(int i=(n) ;i>=0 ;i--)
#define lson num<<1,le,mid
#define rson num<<1|1,mid+1,ri
#define MID int mid=(le+ri)>>1
#define zero(x)((x>0? x:-x)<1e-15)
#define mk make_pair
#define _f first
#define _s second
using namespace std;
//const int INF= ;
typedef long long ll;
//const ll inf =1000000000000000;//1e15;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
//fin.close();
//fout.close();
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);