| ||||||||||
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 |
求大神指点 为什么runtime error#include<iostream> using namespace std; long num[1111]; int n,x,y,ma; struct stage { int x1,x2,h,len; }; int cmp(const void *a,const void *b) {return ((stage*)b)->h-((stage*)a)->h;} stage a[1111]; int dp(int m) { if(num[m]!=0)return num[m]; if(m==n)return 0; int left,right; for(int i=m+1;i<=n;i++) if(a[i].x1<=a[m].x1&&a[i].x2>=a[m].x1) { left=i;a[i].len=a[m].x1; break;} for(int i=m+1;i<=n;i++) if(a[i].x1<=a[m].x2&&a[i].x2>=a[m].x2) { right=i;a[i].len=a[m].x2;break;} if(a[m].h-a[left].h>ma) num[m]=dp(right)+a[m].h-a[right].h+a[m].x2-a[m].len; else if(a[m].h-a[right].h>ma) num[m]=dp(left)+a[m].h-a[left].h+a[m].len-a[m].x1; else num[m]=min(dp(left)+a[m].h-a[left].h+a[m].len-a[m].x1, dp(right)+a[m].h-a[right].h+a[m].x2-a[m].len); return num[m]; } int main() { int text; cin>>text; while(text--) { cin>>n>>x>>y>>ma; for(int i=1;i<=n;i++) cin>>a[i].x1>>a[i].x2>>a[i].h; a[0].x1=a[0].x2=a[0].len=x; a[0].h=y; a[++n].x1=-2000;a[n].x2=2000; a[n].h=0; memset(num,0,sizeof(num)); qsort(a+1,n-1,sizeof(a[0]),cmp); cout<<dp(0)<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator