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 |
Re:代码如下:In Reply To:这题我的算法是将sticks按长宽的和降序排序,再一组组覆盖,但WA,好心的大牛帮我看一下好吗? Posted by:Basara at 2006-08-10 22:30:53 #include <iostream> using namespace std; typedef struct { int len; int wid; }item; item wood[5000]; item queue[5000]; int compare(const void *a, const void *b){ return (*((item *)b)).len +(*((item *)b)).wid -(*((item *)a)).len -(*((item *)a)).wid; } int main(){ //freopen("test.txt","r",stdin); int kase,i,j,n,queuelen,find; scanf("%d",&kase); while(kase--){ scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d%d",&wood[i].len,&wood[i].wid); } qsort(wood,n,sizeof(item),compare); //sort decreasely by sum of len and wid queuelen=0; queue[0]=wood[0]; for(i=1;i<n;i++){ find=0; for(j=0;j<=queuelen;j++){ if(wood[i].len<=queue[j].len && wood[i].wid<=queue[j].wid){ find=1; queue[j]=wood[i]; break; } } if(!find) { queue[++queuelen]=wood[i]; } } printf("%d\n",queuelen+1); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator