codeforces round 360 div2 C Chris and Roads
来源:互联网 发布:linux vi 中替换命令 编辑:程序博客网 时间:2024/06/10 00:25
/*
题目描述:一个人从(0,0)向(0,w)移动,速度是u,一辆车向左移动的速度是v,车的形状是一个凸多边形,
现在要求人不能撞到车,几何解释就是人所在的点不能出现在多边形内部,问人最少多久能通过道路。
思路:以车为参考系,也就是假设车不动,那么人只能向右走或向右上方走,画图可以看出最优的路线要么是一条
不穿过多边形内部的直线,要么先是一段水平的线段,再接一段不穿过多边形内部的直线,根据路径可以确定
时间,具体见代码。
*/
#pragma warning(disable:4786)
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<sstream>
#define LL long long
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define lson l,m,x<<1
#define rson m+1,r,x<<1|1
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
const double eps=1e-6;
const int maxn = 1e6 + 5;
struct node
{
double x , y;
}p[maxn];
int main()
{
int n ;
double w , v , u , a , l , ans = 0 , x , y;
scanf("%d%lf%lf%lf", &n , &w ,&v , &u);
a = atan(u / v);
ans = w / u;
double px = -INF , py = -INF , k , b , tadd = INF;
int flag = 1;
for(int i = 0 ; i< n ;i++){
scanf("%lf%lf", &p[i].x , &p[i].y);
if(p[i].y - u / v * p[i].x > eps){
flag = 0;
}
}
if(flag){ //判断直线可不可以从多边形的左上方穿过
printf("%.10lf\n",ans);
return 0;
}
p[n].x = 0; p[n].y = 0;
for(int i = 0 ; i<= n ; i++){
k = u / v;
b = p[i].y - k * p[i].x;
int tag = 1;
for(int j = 0 ; j<= n ; j++){
if(p[j].y - (k * p[j].x + b) < -eps){
tag = 0;
break;
}
}
if(tag){
tadd = min(tadd , (p[i].x - p[i].y / (u / v)) / v); //找到与直线相切的凸多边形的点,确定一开始横向走的总时间
}
}
ans += tadd;
printf("%.10lf\n",ans);
return 0;
}
题目描述:一个人从(0,0)向(0,w)移动,速度是u,一辆车向左移动的速度是v,车的形状是一个凸多边形,
现在要求人不能撞到车,几何解释就是人所在的点不能出现在多边形内部,问人最少多久能通过道路。
思路:以车为参考系,也就是假设车不动,那么人只能向右走或向右上方走,画图可以看出最优的路线要么是一条
不穿过多边形内部的直线,要么先是一段水平的线段,再接一段不穿过多边形内部的直线,根据路径可以确定
时间,具体见代码。
*/
#pragma warning(disable:4786)
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<sstream>
#define LL long long
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define lson l,m,x<<1
#define rson m+1,r,x<<1|1
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
const double eps=1e-6;
const int maxn = 1e6 + 5;
struct node
{
double x , y;
}p[maxn];
int main()
{
int n ;
double w , v , u , a , l , ans = 0 , x , y;
scanf("%d%lf%lf%lf", &n , &w ,&v , &u);
a = atan(u / v);
ans = w / u;
double px = -INF , py = -INF , k , b , tadd = INF;
int flag = 1;
for(int i = 0 ; i< n ;i++){
scanf("%lf%lf", &p[i].x , &p[i].y);
if(p[i].y - u / v * p[i].x > eps){
flag = 0;
}
}
if(flag){ //判断直线可不可以从多边形的左上方穿过
printf("%.10lf\n",ans);
return 0;
}
p[n].x = 0; p[n].y = 0;
for(int i = 0 ; i<= n ; i++){
k = u / v;
b = p[i].y - k * p[i].x;
int tag = 1;
for(int j = 0 ; j<= n ; j++){
if(p[j].y - (k * p[j].x + b) < -eps){
tag = 0;
break;
}
}
if(tag){
tadd = min(tadd , (p[i].x - p[i].y / (u / v)) / v); //找到与直线相切的凸多边形的点,确定一开始横向走的总时间
}
}
ans += tadd;
printf("%.10lf\n",ans);
return 0;
}
0 0
- codeforces round 360 div2 C Chris and Roads
- Codeforces Round #365 (Div. 2) [C] Chris and Road
- Codeforces Round #365 (Div. 2) C. Chris and Road
- Codeforces Round #365 (Div. 2) C. Chris and Road 【数学】
- codeforces Round#369 div2-D tDirected Roads
- codeforces round#372(div2 C) C. Plus and Square Root
- codeforces#369Div2(711B)Chris and Magic Square
- Codeforces Round #263(div2)C. Appleman and Toastman
- Codeforces Round 264(div2) C. Gargari and Bishops
- Codeforces Round #267 Div2 C George and Job --DP
- Codeforces Round 281 div2 C Vasya and Basketball
- C. Anya and Ghosts(Codeforces Round #288(div2)
- C. Ilya and Sticks(Codeforces Round 297(div2))
- C. Amr and Chemistry(Codeforces Round #312(div2))
- Codeforces Round #403 div2 C. Andryusha and Colored Balloons
- Mike and gcd problem-codeforces-Round 410 Div2-C
- Codeforces Round #360(div2)
- Codeforces Round #365 (Div. 2) C. Chris and Road(计算几何+二分)
- 组合算法
- 过滤器案例之编码问题处理、代理对象的使用、过滤器案例之无效数据的过滤
- Docker配置加速器
- caffe for windows的python接口学习(3):生成以原始图片作为输入的配置文件
- java基础学习第一天
- codeforces round 360 div2 C Chris and Roads
- centos下/etc/sysconfig/下找不到iptables文件
- 前后台交互的传参方式与大参数传递
- YOLOv2如何fine-tuning?
- android应用程序稳定性一点想法
- NO.6 HTML之列表
- 个人网站上线 and 照常的阶段总结
- 三块不相交的k*k方格中数和的最大值(dp)
- Hadoop生态上几个技术的关系与区别:hive、pig、hbase 关系与区别