2016SDAU编程练习二1006
2016-04-16 14:02
302 查看
Line belt
Problem Description
In a two-dimensional plane there are two line belts, there are two segments AB and CD, lxhgww's speed on AB is P and on CD is Q, he can move with the speed R on other area on the plane.<br>How long must he take to travel from A to D?
Input
The first line is the case number T.<br>For each case, there are three lines.<br>The first line, four integers, the coordinates of A and B: Ax Ay Bx By.<br>The second line , four integers, the coordinates of C and D:Cx Cy Dx Dy.<br>The third line, three integers,
P Q R.<br>0<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000<br>1<=P,Q,R<=10
Output
The minimum time to travel from A to D, round to two decimals.
Sample Input
1<br>0 0 0 100<br>100 0 100 100<br>2 2 1
Sample Output
136.60
Author
lxhgww&&momodi
Source
HDOJ Monthly Contest – 2010.05.01
题意:给出两条传送带的起点到末端的坐标,其中ab为p的速度,cd为q的速度 其他地方为r的速度,求a到d点的最短时间
思路:三分法,就是给了两条线段,每条中必定有一点,连接后时间最短
感想:这个就比较复杂一点了
AC代码
#include <cstdio>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<iomanip>
using namespace std;
double p,q,R;
struct point
{
double x;
double y;
point operator / (const point &others)
{
point tt;
tt.x=(this->x+others.x)/2;
tt.y=(this->y+others.y)/2;
return tt;
}
};
double length (point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double find ( point c,point d,point mid )
{
point l,r,mid1,mid2;
double t1,t2;
l=c;r=d;
do
{
mid1=(r/l);
mid2=(r/mid1);
t1=length(mid1,d)/q+length(mid1,mid)/R;
t2=length(mid2,d)/q+length(mid2,mid)/R;
if(t1>t2)
l=mid1;
else
r=mid2;
}while(fabs(t1-t2)>0.00001);
return t2;
}
int main()
{
// freopen("r.txt","r",stdin);
int N;
point a,b,c,d,r,l,mid1,mid2;
double t1,t2;
cin>>N;
while(N--)
{
cin>>a.x>>a.y>>b.x>>b.y;
cin>>c.x>>c.y>>d.x>>d.y;
cin>>p>>q>>R;
l=a;r=b;
do
{
mid1=(r/l);
mid2=(r/mid1);
t1=length(a,mid1)/p+find(c,d,mid1);
t2=length(a,mid2)/p+find(c,d,mid2);
if(t1>t2)
l=mid1;
else
r=mid2;
}while(fabs(t2-t1)>0.00001);
printf("%.2f\n",t2);
}
return 0;
}
Problem Description
In a two-dimensional plane there are two line belts, there are two segments AB and CD, lxhgww's speed on AB is P and on CD is Q, he can move with the speed R on other area on the plane.<br>How long must he take to travel from A to D?
Input
The first line is the case number T.<br>For each case, there are three lines.<br>The first line, four integers, the coordinates of A and B: Ax Ay Bx By.<br>The second line , four integers, the coordinates of C and D:Cx Cy Dx Dy.<br>The third line, three integers,
P Q R.<br>0<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000<br>1<=P,Q,R<=10
Output
The minimum time to travel from A to D, round to two decimals.
Sample Input
1<br>0 0 0 100<br>100 0 100 100<br>2 2 1
Sample Output
136.60
Author
lxhgww&&momodi
Source
HDOJ Monthly Contest – 2010.05.01
题意:给出两条传送带的起点到末端的坐标,其中ab为p的速度,cd为q的速度 其他地方为r的速度,求a到d点的最短时间
思路:三分法,就是给了两条线段,每条中必定有一点,连接后时间最短
感想:这个就比较复杂一点了
AC代码
#include <cstdio>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<iomanip>
using namespace std;
double p,q,R;
struct point
{
double x;
double y;
point operator / (const point &others)
{
point tt;
tt.x=(this->x+others.x)/2;
tt.y=(this->y+others.y)/2;
return tt;
}
};
double length (point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double find ( point c,point d,point mid )
{
point l,r,mid1,mid2;
double t1,t2;
l=c;r=d;
do
{
mid1=(r/l);
mid2=(r/mid1);
t1=length(mid1,d)/q+length(mid1,mid)/R;
t2=length(mid2,d)/q+length(mid2,mid)/R;
if(t1>t2)
l=mid1;
else
r=mid2;
}while(fabs(t1-t2)>0.00001);
return t2;
}
int main()
{
// freopen("r.txt","r",stdin);
int N;
point a,b,c,d,r,l,mid1,mid2;
double t1,t2;
cin>>N;
while(N--)
{
cin>>a.x>>a.y>>b.x>>b.y;
cin>>c.x>>c.y>>d.x>>d.y;
cin>>p>>q>>R;
l=a;r=b;
do
{
mid1=(r/l);
mid2=(r/mid1);
t1=length(a,mid1)/p+find(c,d,mid1);
t2=length(a,mid2)/p+find(c,d,mid2);
if(t1>t2)
l=mid1;
else
r=mid2;
}while(fabs(t2-t1)>0.00001);
printf("%.2f\n",t2);
}
return 0;
}
相关文章推荐
- spring annotation
- Java基础(容易忽略的java细节)
- Spring注解式与配置文件式
- Struts2之ModelDriven的使用
- vsftpd.conf 详解
- PROCESS_YIELD()宏和C语言的switch语句
- struts2中的ModelDriven使用
- Struts2中的ModelDriven机制及其运用
- 设计模式中的单例模式&c++
- Java中关于异常的一些问题(三)
- Java中关于异常的一些问题(三)
- 给Eclipse提速的7个技巧
- Python 练习实例24
- Java中基本类型
- Spring@Autowired注解与自动装配
- [树上倍增] BZOJ 4281 [ONTAK2015]Związek Harcerstwa Bajtockiego
- QT中QProcess调用命令行的痛苦经历
- 2016SDAU编程练习二1005
- Google Code Jam 2016 Round 1A
- [学习笔记]Java正则表达式