标签:
这道题,包大人意思说500秒是一个时代的终结,于是我开始用2个优先队列滚动模拟500秒前的状态,果断超时了。。
这道题,数据50000个,然而只有开始500m,这样相同速度重复的就很多了,按照速度保存,然后判断的时候,就判断这个速度下最快的那一个,就(比一开始的想法)节约了好多
#include<cstdio>
#include<queue>
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
const int maxn=50010;
int ans[maxn];
//int flag[maxn];
struct ways
{
int first;
int who;
ways(int a,int b)
{
first=a;
who=b;
}
bool operator<(const ways&wakaka)const
{
if(first==wakaka.first)
{
return who>wakaka.who;
}
return first<wakaka.first;
}
};
priority_queue<ways>speed[101];
int main()
{
int T;
scanf("%d",&T);
int ii=0;
while(T--)
{
//memset(flag,0,sizeof(flag));
int n;
scanf("%d",&n);
int mf,mv;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&mf,&mv);
speed[mv].push(ways(mf,i));
}
int cnt=0;
int i;
for(i=0;i<=502;i++)
{
int maxlen=0;
int maxwho;
int maxv=1;
for(int j=1;j<=100;j++)
{
if(!speed[j].empty())
{
//cout<<j<<endl<<endl;
if(maxlen<i*j+speed[j].top().first)
{
maxwho=speed[j].top().who;
maxlen=i*j+speed[j].top().first;
maxv=j;
}
else if(maxlen==i*j+speed[j].top().first)
{
if(maxwho>speed[j].top().who)
{
maxwho=speed[j].top().who;
maxv=j;
}
}
}
}
speed[maxv].pop();
cnt++;
ans[cnt]=maxwho;
if(cnt==n)
break;
}
//cout<<speed[1].top().who<<endl;
ii++;
printf("Case #%d:\n",ii);
for(int j=100;j>=1;j--)
{
while(!speed[j].empty())
{
//cout<<speed[j].top().first<<endl;
cnt++;
ans[cnt]=speed[j].top().who;
speed[j].pop();
}
}
for(i=1;i<=n;i++)
{
printf("%d",ans[i]);
if(i!=n)
{
printf(" ");
}
else
{
printf("\n");
}
}
}
return 0;
}
我的代码风格实在太差,不过这几天会改变。。。
标签:
原文地址:http://blog.csdn.net/qq_32995183/article/details/51366253