首页 > 代码库 > CodeForces 703C Chris and Road (简单几何)

CodeForces 703C Chris and Road (简单几何)

题意:有一个n边形的汽车向以速度v向x轴负方向移动,给出零时时其n个点的坐标。并且有一个人在(0,0)点,可以以最大速度u通过w宽的马路,到达(0,w)点。现在要求人不能碰到汽车,人可以自己调节速度。问人到达马路对面的最小时间是多少?

析:这个题是一个简单的分类讨论,很明显只有两种情况,第一种,直接到达w,不会被车撞到,答案就是w/u,

第二种是切着车过去,或者是等车过去再过去,只要枚举车的每个顶点,找到最后通过y轴的点就好,或者根本不会与车相切。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 2e5 + 10;
const int mod = 1000000007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
  return r >= 0 && r < n && c >= 0 && c < m;
}

int main(){
  int w, u, v;
  scanf("%d %d %d %d", &n, &w, &v, &u);
  bool ok = true;
  double ans = 0.0;
  for(int i = 0; i < n; ++i){
    int x, y;
    scanf("%d %d", &x, &y);
    double t1 = x * 1.0 / v;
    double t2 = y*1.0 / u;
    if(t1 < t2)  ok = false;
    ans = max(ans,t1 + (w-y)*1.0 / u);
  }
  if(ok)  printf("%.6f\n", w*1.0/u);
  else  printf("%.6f\n", max(ans, w*1.0/u));
  return 0;
}

  

CodeForces 703C Chris and Road (简单几何)