UVA11796- Dog Distance

题意是给出两条轨迹,分别给出起点和终点,要求两条轨迹同时开始跑,同时到达重点


问,中途两点间最大距离和最小距离的差值


我的做法:


设一个速度,用向量法模拟过程


我的代码:

#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const double inf=1e9;
struct dot
{
	double x,y;
	dot(){}
	dot(double a,double b){x=a;y=b;}
	dot operator +(dot a){return dot(x+a.x,y+a.y);}
	dot operator -(dot a){return dot(x-a.x,y-a.y);}
	dot operator *(double a){return dot(x*a,y*a);}
	double operator *(dot a){return x*a.y-y*a.x;}
	dot operator /(double a){return dot(x/a,y/a);}
	double operator /(dot a){return x*a.x+y*a.y;}
	bool operator ==(dot a){return x==a.x&&y==a.y;}
	void in(){scanf("%lf%lf",&x,&y);}
	void out(){printf("%lf %lf",x,y);}
	double mod(){return sqrt(x*x+y*y);}
	double dis(dot a){return sqrt(pow(x-a.x,2)+pow(y-a.y,2));}
};
double mxd(dot a,dot b,dot c)
{
	return max(a.dis(b),a.dis(c));
}
double mnd(dot a,dot b,dot c)
{
	if((a-b)/(c-b)<=0)
		return a.dis(b);
	if((a-c)/(b-c)<=0)
		return a.dis(c);
	return fabs((a-b)*(c-b)/b.dis(c));
}
int main()
{
	double va,vb,mx,mn;
	dot a[110],b[110],sa,sb,s,e,ta,tb,v,t;
	int i,j,T,TT,n,m;
	cin>>T;
	for(TT=1;TT<=T;TT++)
	{
		mx=0;
		mn=inf;
		cin>>n>>m;
		for(i=0;i<n;i++)
			a[i].in();
		va=0;
		for(i=1;i<n;i++)
			va+=a[i-1].dis(a[i]);
		for(i=0;i<m;i++)
			b[i].in();
		vb=0;
		for(i=1;i<m;i++)
			vb+=b[i-1].dis(b[i]);
		sa=a[0];sb=b[0];
		i=j=1;
		while(i<n&&j<m)
		{
			ta=a[i]-sa;
			ta=ta/ta.mod();
			ta=ta*va;
			tb=b[j]-sb;
			tb=tb/tb.mod();
			tb=tb*vb;
			if(sa.dis(a[i])/va>sb.dis(b[j])/vb)
			{
				v=tb-ta;
				t=sa;
				s=sb;
				e=s+v*(sb.dis(b[j])/vb);
				sa=sa+ta*(sb.dis(b[j])/vb);
				sb=b[j++];
			}
			else
			{
				v=ta-tb;
				t=sb;
				s=sa;
				e=s+v*(sa.dis(a[i])/va);
				sb=sb+tb*(sa.dis(a[i])/va);
				sa=a[i++];
			}
			mx=max(mx,mxd(t,s,e));
			mn=min(mn,mnd(t,s,e));
		}
		printf("Case %d: %.0lf\n",TT,mx-mn);
	}
}

原题:

Download as PDF


 

C

Dog Distance

Input

Standard Input

Output

Standard Output

Two dogs, Ranga and Banga, are running randomly following two different paths. They both run for T seconds with different speeds. Ranga runs with a constant speed of R m/s, whereas Banga runs with a constant speed of S m/s. Both the dogs start and stop at the same time. Let D(t) be the distance between the two dogs at time t.

The dog distance is equal to the difference between the maximum and the minimum distance between the two dogs in their whole journey.

 

Mathematically,

Dog Distance = {max (D(a)) 0 <= a <= T} – {min (D(b))  0 <= b <= T}

Given the paths of the two dogs, your job is to find the dog distance.

Each path will be represented using N points, (P1 P2 P3 ... PN). The dog following this path will start from P1 and follow the line joining with P2, and then it will follow the line joining P2-P3, then P3-P4 and so on until it reaches Pn.

Input

Input starts with an integer I(I1000), the number of test cases.

Each test case starts with 2 positive integers A(2A50),B(2B50). The next line contains the coordinates of A points with the format X1 Y1 X2 Y2 ...XA YA, (0Xi,Yi1000). These points indicate the path taken by Ranga. The next line contains B points in the same format. These points indicate the path taken by Banga. All distance units are given in meters and consecutive points are distinct. All the given coordinates are integers.

Note that the values of T, R and S are unknown to us.

Output

For each case, output the case number first. Then output the dog distance rounded to the nearest integer. Look at the samples for exact format.

 

 

Sample Input

Sample Output

2

2 2

0 0 10 0

0 1 10 1

3 2

635 187 241 269 308 254

117 663 760 413

 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值