您的位置:首页 > 理论基础 > 数据结构算法

hdu 4393 优先队列

2017-02-11 12:21 274 查看
//
//  main.cpp
//  STL-优先队列
//
//  Created by liuzhe on 16/12/21.
//  Copyright © 2016年 my_code. All rights reserved.
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;

struct node
{
int f,id;
bool operator <(const node &b)const
{
return (f<b.f||(f==b.f&&id>b.id));
}
};
priority_queue<node> s[105];
int main(int argc, const char * argv[]) {
// insert code here...
int t;
cin>>t;
int cas=1;
while(t--)
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
node t;
int f,d;
scanf("%d%d",&f,&d);
t.f = f;
t.id = i;
s[d].push(t);
}
printf("Case #%d:\n",cas++);
for(int i=1;i<=n;i++)
{
int maxx = -1;
int minid = 100000000;
int ans;
for(int j=1;j<=100;j++)
if(!s[j].empty())
{
node t = s[j].top();
if((i-1)*j+t.f>maxx||((i-1)*j+t.f==maxx&&t.id<minid))
{
maxx = (i-1)*j+t.f;
ans = j;
minid = t.id;
}
}
int tmp = s[ans].top().id;
if(i!=n)
printf("%d ",tmp);
else
printf("%d\n",tmp);
s[ans].pop();
}
}
//std::cout << "Hello, World!\n";
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息