| ||||||||||
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,请各位帮忙看下#include<iostream> #include<cstdio> #include<algorithm> using namespace std; struct node //平台 { long x1,x2,h,pos,min; //min记录到达的最短时间 bool flip,f,r; //是否可以到达,f,r记录此木板左右是否已到达相应木板 }flat[1010]; int queue[1010]; int compare(node a,node b) { return a.h>b.h; } void init() //初始化 { int i; for(i=0;i<1010;i++) { flat[i].x1=0; flat[i].x2=0; flat[i].h=0; flat[i].flip=0; flat[i].f=0; flat[i].r=0; flat[i].pos=0X7fffffff; flat[i].min=0X7fffffff; } } int main() { #ifndef ONLINE_JUDGE freopen ("Help Jimmy.txt","r",stdin); #endif bool flag,reach; int i,j,k,t,m; int front,rear; long N,X,Y,MAX; long min; scanf("%d",&t); for(k=1;k<=t;k++) { init(); front=rear=0; scanf("%ld %ld %ld %ld",&N,&X,&Y,&MAX); for(i=0;i<N;i++) { scanf("%ld %ld %ld",&flat[i].x1,&flat[i].x2,&flat[i].h); } flat[N].x1=-20010; flat[N].x2=20010; flat[N].h=0; sort(flat,flat+N+1,compare); j=0; while(flat[j].x1>X || flat[j].x2<X || Y<flat[j].h) { j++; } queue[rear++]=j; flat[j].pos=X; flat[j].min=Y-flat[j].h; flat[j].flip=1; while(front!=rear) { flag=true; j=1; while(flag) { if(j+queue[front]>=N+1) { flag=false; continue; } if(flat[queue[front]].h-flat[queue[front]+j].h>MAX) { flag=false; continue; } if(flat[queue[front]].f==0 && flat[queue[front]].x1>=flat[queue[front]+j].x1 && flat[queue[front]].x1<=flat[queue[front]+j].x2) { flat[queue[front]].f=1; if(flat[queue[front]+j].min>flat[queue[front]].h-flat[queue[front]+j].h+flat[queue[front]].pos-flat[queue[front]].x1+flat[queue[front]].min) { flat[queue[front]+j].pos=flat[queue[front]].x1; flat[queue[front]+j].min=flat[queue[front]].h-flat[queue[front]+j].h+flat[queue[front]].pos-flat[queue[front]].x1+flat[queue[front]].min; } if(flat[queue[front]+j].flip==0) { queue[rear++]=queue[front]+j; flat[queue[front]+j].flip=1; } } if(flat[queue[front]].r==0 && flat[queue[front]].x2>=flat[queue[front]+j].x1 && flat[queue[front]].x2<=flat[queue[front]+j].x2) { flat[queue[front]].r=1; if(flat[queue[front]+j].min>flat[queue[front]].h-flat[queue[front]+j].h+flat[queue[front]].x2-flat[queue[front]].pos+flat[queue[front]].min) { flat[queue[front]+j].pos=flat[queue[front]].x2; flat[queue[front]+j].min=flat[queue[front]].h-flat[queue[front]+j].h+flat[queue[front]].x2-flat[queue[front]].pos+flat[queue[front]].min; } if(flat[queue[front]+j].flip==0) { queue[rear++]=queue[front]+j; flat[queue[front]+j].flip=1; } if(flat[queue[front]].f==1 && flat[queue[front]].r==1) { flag=false; continue; } } j++; } front++; } printf("%ld\n",flat[N].min); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator