Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 优先队列

Posted by 15926228182 at 2013-08-19 15:53:30 on Problem 2051
```第一次做，竟然1A，**人民发来贺电。还没有用STL的水过

#include <cstdio>
using namespace std;
#define N 3010
int ids[N],time[N][2];//time数组有一个保存原值
void swap(int &a,int &b)
{
a=a^b;b=a^b;a=a^b;
}
{
while(1)
{
if(((i<<1)<=n&&(time[i<<1][0]<time[i][0]||(time[i<<1][0]==time[i][0]&&ids[i<<1]<ids[i])))||((i<<1|1)<=n&&(time[i<<1|1][0]<time[i][0]||(time[i<<1|1][0]==time[i][0]&&ids[i<<1|1]<ids[i]))))
{
i<<=1;
if(i+1<=n&&(time[i+1][0]<time[i][0]||(time[i+1][0]==time[i][0]&&ids[i+1]<ids[i]))){
swap(time[i>>1][0],time[i+1][0]);
swap(time[i>>1][1],time[i+1][1]);
swap(ids[i>>1],ids[++i]);
}
else{
swap(time[i>>1][0],time[i][0]);
swap(time[i>>1][1],time[i][1]);
swap(ids[i>>1],ids[i]);
}
}
else break;
}
}
void BuildHeap(int n)//初始化堆
{
for(int i=n>>1;i>=1;i--)
}
void FilterHeap(int n,int k)//输出根，改变根，调整根
{
BuildHeap(n);
while(k--)
{
time[1][0]+=time[1][1];
printf("%d\n",ids[1]);
}
}
int main()
{
char s[10];
int n=0,k;
while(scanf("%s",s)&&s[0]!='#'){
++n;
scanf("%d %d",&ids[n],&time[n][0]);
time[n][1]=time[n][0];
}
scanf("%d",&k);
FilterHeap(n,k);
//BuildHeap(n);
//for(int i=1;i<=n;i++)
//	printf("(%d,%d) ",ids[i],time[i]);
return 0;
}
```

Followed by: