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

为什么超时?? 大牛们帮忙看看,谢谢。。

Posted by kamel52045386 at 2007-10-02 18:34:31 on Problem 2051
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 typedef struct
 {
  int id;
  int timeout;
  int origin;
 }queue;
 
 int cmp(const void *e,const void *f)
 {  
   queue *a=((queue *)e);
   queue *b=((queue *)f);
  if(a->timeout<b->timeout)
	  return -1;
    if(a->timeout>b->timeout)
		return 1;
	 if(a->timeout==b->timeout)
		 return (a->id>b->id);
 }

void main()
{
 int q_num,i,k; 

 queue q[1005];
 char reg[10];
 scanf("%s",reg);
 q_num=i=0;
  while(reg[0]!='#')
  {
   q_num++;
   scanf("%d %d",&q[i].id,&q[i].timeout);
   getchar();
   q[i].origin=q[i].timeout;
   i++;
   scanf("%s",reg);
 
  }
   scanf("%d",&k);
   qsort(q,q_num,sizeof(q[0]),cmp);
   for(i=0;i<k;i++)
   {
   printf("%d\n",q[0].id);
   q[0].timeout+=q[0].origin;//每次排序之后将时间的加上周期重新排序
   qsort(q,q_num,sizeof(q[0]),cmp);
   }

}

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