Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么超时?? 大牛们帮忙看看,谢谢。。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator