| ||||||||||
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 |
WA!!help!!!#include <iostream.h> #include <stdlib.h> #include <stdio.h> #include <math.h> int N,X,Y,max,min; int feet; struct board { int x1,x2,height,left,right; board* pleft; board* pright; }; int mycompare(const void *p1,const void *p2) { board *pp1=(board*)p1; board *pp2=(board*)p2; if (pp1->height == pp2->height ) return (pp1->x1-pp2->x1); return (pp2->height-pp1->height); } board list[1001]; board* findboard(board *root,int num,int x)//找到下一个要跳的板子 { for (int a=num+1;a<N;a++) { if (root->height-list[a].height>0&&root->height-list[a].height<=max &&list[a].x1<=x&&list[a].x2>=x) { list[a].left=fabs(list[a].x1-x); list[a].right=fabs(list[a].x2-x); return &list[a]; } } if (a==N&&root->height<=max)//直接到达地面 { board * ground=new board; ground->height=0; ground->x1=x; ground->x2=x; ground ->left=0; ground->right=0; ground->pleft=NULL; ground->pright=NULL; return ground; } else return NULL;//摔死 } int shorter(int num1,int num2) { return (num1<num2?num1:num2); } int distance(board *begin) { if (begin==NULL) { return pow(2,30);//返回一个大数 } else if (begin->x1==begin->x2)//已经到达地面 return 0; else //递归 return shorter(begin->left+distance(begin->pleft),begin->right+distance(begin->pright)); } void main() { int n; scanf("%d",&n); while (n--) { scanf("%d%d%d%d",&N,&X,&Y,&max); for (int b=0;b<N;b++) { list[b].pleft=NULL; list[b].pright=NULL; } for (int i=0;i<N;i++) { scanf ("%d%d%d",&(list[i].x1),&(list[i].x2),&(list[i].height)); } qsort(list,N,sizeof (board),mycompare); //按高度从大到小排序 for (int k=0;k<N;k++) { if (list[k].x1<=X&&list[k].x2>=X) { list[k].left=X-list[k].x1; list[k].right=list[k].x2-X; break; } }//寻找第一块板 if (k==N) { cout << Y<<endl; return ; }//直接到达地面 for (int j=k;j<N;j++) { list[j].pleft=findboard(&list[j],j,list[j].x1); list[j].pright=findboard(&list[j],j,list[j].x2); } feet=distance (list+k); printf("%d\n",feet+Y); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator