• 帮助Jimmy


    //帮助Jimmy
    
    #include<stdio.h>
    #include<memory.h>
    #include<stdlib.h>
    #define MAX_N 1000
    #define INFINITE 1000000
    int t,n,x,y,max;
    struct Platform{
    	int Lx,Rx,h;
    };
    Platform aPlatform[MAX_N+10];
    int aLeftMinTime[MAX_N+10];
    int aRightMinTime[MAX_N+10];
    int MyCompare(const void *e1,const void *e2)
    {
    	Platform *p1,*p2;
    	p1=(Platform *)e1;
    	p2=(Platform *)e2;
    	return p2->h-p1->h;
    }
    int MinTime(int L,bool bLeft)
    {
    	int y=aPlatform[L].h;
    	int x;
    	if(bLeft)
    		x=aPlatform[L].Lx;
    	else
    		x=aPlatform[L].Rx;
    	int i;
    	for(i=L+1;i<=n;i++){
    		if(aPlatform[i].Lx<=x&&aPlatform[i].Rx>=x)
    			break;
    	}
    	if(i<=n){
    		if(y-aPlatform[i].h>max)
    			return INFINITE;
    	}else{
    		if(y>max)
    			return INFINITE;
    		else
    			return y;
    	}
    	int nLeftTime=y-aPlatform[i].h+x-aPlatform[i].Lx;
    	int nRightTime=y-aPlatform[i].h+aPlatform[i].Rx-x;
    	if(aLeftMinTime[i]==-1)
    		aLeftMinTime[i]=MinTime(i,true);
    	if(aRightMinTime[i]==-1)
    		aRightMinTime[i]=MinTime(i,false);
    	nLeftTime+=aLeftMinTime[i];
    	nRightTime+=aRightMinTime[i];
    	if(nLeftTime<nRightTime)
    		return nLeftTime;
    	return nRightTime;
    }
    int main()
    {
    	scanf("%d",&t);
    	for(int i=0;i<t;i++){
    		memset(aLeftMinTime,-1,sizeof(aLeftMinTime));
    		memset(aRightMinTime,-1,sizeof(aRightMinTime));
    		scanf("%d%d%d%d",&n,&x,&y,&max);
    		aPlatform[0].Lx=x;
    		aPlatform[0].Rx=x;
    		aPlatform[0].h=y;
    		for(int j=1;j<=n;j++)
    			scanf("%d%d%d",&aPlatform[j].Lx,&aPlatform[j].Rx,&aPlatform[j].h);
    		qsort(aPlatform,n+1,sizeof(Platform),MyCompare);
    		printf("%d
    ",MinTime(0,true));
    	}
    	return 0;
    }

  • 相关阅读:
    【Codeforces 923A】Primal Sport
    【Codeforces 924C】Riverside Curio
    【Codeforces 682C】Alyona and the Tree
    【Codeforces 1118D1】Coffee and Coursework (Easy version)
    【Codeforces 493C】Vasya and Basketball
    【Codeforces 598D】Igor In the Museum
    js 时间格式化
    C#自定义规则对比两个集合的对象是否相等
    VUE的组件DEMO
    js 去掉指定符号的字符串做法
  • 原文地址:https://www.cnblogs.com/javafly/p/6037171.html
Copyright © 2020-2023  润新知