codeforces - 703C - Chris and Road(几何)
2016-11-20 00:16
357 查看
LINK:http://codeforces.com/contest/703/problem/C
题意:有一个长成多边形的车,和一个在(0,0)点可视作点的人。
人以u的速度朝y轴正方向走。
车以v的速度朝x轴负方向走。
车不能撞到人(就是人的点在任意时刻不能出现在车的n边形内)。
求人到达y=w这条线的最小时间。
解法:
对于车来说人相当于向上和向右走。
如图,长箭头表示以车为参照系人的运动情况。
所以就是两种情况:
1.多边形和射线不相交
2.相交
1的话人直接走就是。
2的话处理下平移下直线让多边形和直线相切。然后再算直接走的。
第一次写计算几何orzzzz板子真的不会用,2d总之3d混用了【】【】】。
题意:有一个长成多边形的车,和一个在(0,0)点可视作点的人。
人以u的速度朝y轴正方向走。
车以v的速度朝x轴负方向走。
车不能撞到人(就是人的点在任意时刻不能出现在车的n边形内)。
求人到达y=w这条线的最小时间。
解法:
对于车来说人相当于向上和向右走。
如图,长箭头表示以车为参照系人的运动情况。
所以就是两种情况:
1.多边形和射线不相交
2.相交
1的话人直接走就是。
2的话处理下平移下直线让多边形和直线相切。然后再算直接走的。
第一次写计算几何orzzzz板子真的不会用,2d总之3d混用了【】【】】。
#include<bits/stdc++.h> using namespace std; #define eps 1e-8 #define zero(x) (((x)>0?(x):-(x))<eps) struct point3 { double x, y, z = 0; bool f = 0; } a[10010]; struct line3 { point3 a, b; } key; double distance(point3 p1, point3 p2) { return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); } point3 subt(point3 u, point3 v) { point3 ret; ret.x = u.x - v.x; ret.y = u.y - v.y; ret.z = u.z - v.z; return ret; } double dmult(point3 u, point3 v) { return u.x * v.x + u.y * v.y + u.z * v.z; } point3 xmult(point3 u, point3 v) { point3 ret; ret.x = u.y * v.z - v.y * u.z; ret.y = u.z * v.x - u.x * v.z; ret.z = u.x * v.y - u.y * v.x; return ret; } point3 intersection(point3 u1, point3 u2, point3 v1, point3 v2) { point3 ret = u1; double t = ((u1.x - v1.x) * (v1.y - v2.y) - (u1.y - v1.y) * (v1.x - v2.x)) / ((u1.x - u2.x) * (v1.y - v2.y) - (u1.y - u2.y) * (v1.x - v2.x)); ret.x += (u2.x - u1.x) * t; ret.y += (u2.y - u1.y) * t; return ret; } point3 ptoline(point3 p, point3 l1, point3 l2) { point3 t = p; t.x += l1.y - l2.y, t.y += l2.x - l1.x; return intersection(p, t, l1, l2); } int same_side(point3 p1, point3 p2, line3 l) { return dmult(xmult(subt(l.a, l.b), subt(p1, l.b)), xmult(subt(l.a, l.b), subt(p2, l.b))) > eps; } int main() { int n; double s, v, u; cin >> n >> s >> v >> u; point3 zer, p1, b; zer.x = 0, zer.y = 0; p1.y = u, p1.x = v; b.x = 0, b.y = 1; key.a = zer, key.b = p1; bool f = 0; for(int i = 0; i < n; i++) { cin >> a[i].x >> a[i].y; //if(f == 1)continue; a854 if(same_side(a[i], b, key)==0) { a[i].f = 1; } if(i!=0&&a[i].f!=a[i-1].f)f = 1; } double d = 0; if(f == 0) { double ans = s / u; printf("%.10f\n", ans); } else { //cout<<"winwin"<<endl; for(int i = 0; i < n; i++) { if(a[i].f == true) { point3 tmp = ptoline(a[i], key.a, key.b); //cout<<" **** "<<tmp.x<<" "<<tmp.y<<endl; double fuck=distance(tmp,a[i]); //cout<<fuck<<endl; if(fuck > d) d=fuck; } } d*=sqrt(u*u+v*v)/u; d/=v; double ans=s/u; ans+=d; //cout<<"d="<<d<<endl; printf("%.10f\n", ans); } return 0; }
相关文章推荐
- 【23.15%】【codeforces 703C】Chris and Road
- 【CodeForces】703C - Chris and Road(思维,好题)
- CodeForces 703 C.Chris and Road(贪心)
- codeforces 703 C. Chris and Road
- [CF 703C]Chris and Road
- Codeforces Round #365 (Div. 2) C. Chris and Road(计算几何+二分)
- Codeforces Round #365 (Div. 2) C. Chris and Road(计算几何+二分)
- codeforces 711B - Chris and Magic Square(矩阵0位置填数)
- 暑假练习赛 003 B Chris and Road
- codeforces 711 B. Chris and Magic Square (简单)
- Codeforces 32E Hide-and-Seek 乞讨2关于镜面反射点 计算几何
- Codeforces Round #365 (Div. 2) -- C. Chris and Road (思路水题)
- CodeForces 935C Fifa and Fafa 计算几何
- Codeforces 32E Hide-and-Seek 求2点关于镜面反射 计算几何
- Codeforces 711B. Chris and Magic Square
- Codeforces Round #365 (Div. 2) C. Chris and Road
- CodeForces 711B - Chris and Magic Square
- Codeforces-Good Bye 2017 C. New Year and Curling(计算几何)
- 【想清楚】Chris and Road
- CodeForces 613 A. Peter and Snow Blower(计算几何)