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> struct monkey { long x; long y; }; struct node { struct monkey pos; struct node * pnext; }; int main() { int n,i; while(scanf("%d",&n),n!=0) { struct monkey temp; struct node *phead,*ptemp,*ptail; phead=(struct node*)malloc(sizeof(struct node)); phead->pnext=NULL; for(i=0;i<n;++i) { ptemp=(struct node*)malloc(sizeof(struct node)); ptemp->pnext=NULL; scanf("%d %d",&ptemp->pos.x,&ptemp->pos.y); if(i==0) { temp.x=ptemp->pos.x; temp.y=ptemp->pos.y; phead=ptemp; ptail=ptemp; } else { if(temp.x < ptemp->pos.x || temp.x==ptemp->pos.x&&temp.y < ptemp->pos.y) { temp.x=ptemp->pos.x; temp.y=ptemp->pos.y; } ptail->pnext=ptemp; ptail=ptemp; } } int count=0; do { ++count; for(ptemp=phead,ptail=phead;ptemp!=NULL;) { if(ptemp->pos.x<=temp.x && ptemp->pos.y<=temp.y) { if(ptemp==phead) { phead=phead->pnext; ptemp=phead; ptail=phead; } else { ptail->pnext=ptemp->pnext; ptemp=ptail->pnext; } } else { ptail=ptemp; ptemp=ptemp->pnext; } } for(ptemp=phead;ptemp!=NULL;ptemp=ptemp->pnext) { if(ptemp==phead||temp.x>ptemp->pos.x || temp.x==ptemp->pos.x&&temp.y > ptemp->pos.y) { temp.x=ptemp->pos.x; temp.y=ptemp->pos.y; } } }while(phead!=NULL); printf("%d\n",count); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator