• 【NOIP2016提高A组模拟8.14】传送带


    题目

    在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段。两条传送带分别为线段AB和线段CD。FTD在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R。现在FTD想从A点走到D点,他想知道最少需要走多长时间

    分析

    易得,答案就是首先在AB上走一段,然后走到CD上的一点,再走到D。
    正解就是三分套三分,但本人很懒,打了个枚举加三分,勉强卡了过去。
    首先在AB上枚举一点,接着在CD上按时间三分。

    #include <cmath>
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    const double maxlongint=2147483647.0;
    const int mo=1000000007;
    const int N=50005;
    using namespace std;
    double ax,ay,bx,by,cx,cy,dx,dy,sp1,sp2,sp3,ans=maxlongint;
    double dis1,dis2,dis3;
    double gg(double x,double y,double x1,double y1)
    {
    	return sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
    }
    double solve(double z1,double z2,double z3) 
    {
    	return z1*z3/z2;
    }
    int main()
    {
    	scanf("%lf %lf %lf %lf
    %lf %lf %lf %lf
    %lf %lf %lf",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy,&sp1,&sp2,&sp3);
    	dis1=gg(ax,ay,bx,by);
    	dis2=gg(cx,cy,dx,dy);
    	for(double i=0;i<=dis1;i+=0.01)
    	{
    		double x,y;
    		double p=solve(i,dis1,abs(bx-ax));
    		if(bx<ax) 
    			x=ax-p;
    		else 
    			x=ax+p;
    		p=solve(i,dis1,abs(by-ay));
    		if(by<ay) 
    			y=ay-p;
    		else 
    			y=ay+p;
    		double l=0,r=dis2;
    		while(l+0.001<=r)
    		{
    			double mid1=l+(r-l)/3,mid2=r-(r-l)/3;
    			double x1,y1,x2,y2;
    			p=solve(mid1,dis2,abs(dx-cx));
    			if(dx<cx) 
    				x1=cx-p;
    			else 
    				x1=cx+p;
    			p=solve(mid1,dis2,abs(dy-cy));
    			if(dy<cy) 
    				y1=cy-p;
    			else 
    				y1=cy+p;
    			double rx,ry;
    			p=solve(mid2,dis2,abs(dx-cx));
    			if(dx<cx) 
    				x2=cx-p;
    			else 
    				x2=cx+p;
    			p=solve(mid2,dis2,abs(dy-cy));
    			if(dy<cy) 
    				y2=cy-p;
    			else 
    				y2=cy+p;
    			if(gg(x,y,x1,y1)/sp3+gg(x1,y1,dx,dy)/sp2<gg(x,y,x2,y2)/sp3+gg(x2,y2,dx,dy)/sp2)
    				r=mid2;
    			else l=mid1;
    		}
    		double x1,y1;
    			if(cx>dx)
    				x1=cx-l/dis2*(cx-dx);
    					else
    					x1=cx+l/dis2*(dx-cx);
    			if(cy>dy) 
    				y1=cy-l/dis2*(cy-dy);
    					else
    						y1=cy+l/dis2*(dy-cy);
    		ans=min(i/sp1+gg(x,y,x1,y1)/sp3+gg(x1,y1,dx,dy)/sp2,ans);
    	}
    	printf("%.2lf",ans);
    }
    
  • 相关阅读:
    某些输入文件使用或覆盖了已过时的 API
    laravel 重写以及500错误
    Ubuntu镜像使用帮助
    E: Sub-process /usr/bin/dpkg returned an error code (1) 解决方案
    python请求java Selenium Webdriver
    Selenium Grid 简易安装
    selenium + python 添加等待时间
    selenium帮助手册以及 webdriver的各种driver
    thinkphp结合layui上传图片
    thinkphp----替换写标签的方法
  • 原文地址:https://www.cnblogs.com/chen1352/p/9043506.html
Copyright © 2020-2023  润新知