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

为什么wa?哪位牛人可以帮小妹看一下吗?

Posted by aime at 2006-08-09 20:37:56 on Problem 2051
#include<iostream>
using namespace std;
int num,k;
struct command{
    int q_num;
	int period;
	int nextime;
}query[1001];
void copy(int s,int j){
    query[s].nextime=query[j].nextime;
	query[s].period=query[j].period;
	query[s].q_num=query[j].q_num;
}
int compare(int i,int j){
    if(query[i].nextime<query[j].nextime)
		return -1;
	if(query[i].nextime>query[j].nextime)
		return 1;
	if(query[i].q_num<query[j].period)
		return -1;
	if(query[i].q_num>query[j].q_num)
		return 1;
	return 0;
}
void HeapAdjust(int s){
	int j;
    copy(0,s);
	for(j=s*s;j<=num;j*=2){
	    if(j<num&&compare(j,j+1)>0)
			++j;
		if(compare(0,j)<=0)
			break;
		copy(s,j);
		s=j;
	}
	copy(s,0);

}
int HeapSort(){
	int left,right;
	for(left=num/2;left>=1;left--)
		HeapAdjust(left);
	for(right=1;right<=k;right++)
	{   
		printf("%d\n",query[1].q_num);
		query[1].nextime+=query[1].period;
	    HeapAdjust(1);
	}
		  return 0;
		  
}
int main(){
	int i,j,q_num,period;
	char c[9];
	//freopen("test.txt","r",stdin);
	i=1;
	cin>>c;
	while(strcmp(c,"#")){
	    cin>>q_num>>period;
        query[i].nextime=period;
		query[i].period=period;
		query[i].q_num=q_num;
		i++;
		cin>>c;
	}
	num=i-1;
	cin>>k;
	HeapSort();
	return 0;
}




Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator