zoukankan      html  css  js  c++  java
  • LA 7158. ACM-ICPC World Finals 2015 I. Ship Traffic

    在区间首尾分别+1 -1的方法叫扫描线??

    #include <iostream>
    #include <algorithm>
    using std::cin;
    struct Moment {
      double value; short weight;
      bool operator < (const Moment &mo2) {
        return value == mo2.value ? weight < mo2.weight : value < mo2.value;
      }
    };
    
    Moment mo[200002];
    int cnt;
    void add_time(double v, int w) {
      mo[cnt].value = v;
      mo[cnt].weight = w;
      cnt++;
    }
    
    int main() {
      std::ios::sync_with_stdio(false);
    
      int n; double w, u, v, t1, t2;
      cin >> n >> w >> u >> v >> t1 >> t2;
      cnt = 0;
      add_time(t1, 0);
      add_time(t2, 0);
    
      for (int i = 0; i < n; ++i) {
        char ch_dir; int m;
        cin >> ch_dir >> m;
        int dir = (ch_dir == 'W') ? 1 : -1;
        while (m--) {
          double len, pos;
          cin >> len >> pos;
          double start_time = std::max(dir * pos / u - w * (i + 1) / v, t1),
                 end_time = std::min((dir * pos + len) / u - w * i / v, t2);
          if (start_time >= t2 || end_time <= t1)
            continue;
          add_time(start_time, 1);
          add_time(end_time, -1);
        }
      }
    
      std::sort(mo, mo + cnt);
    
      double ans = 0;
      for (int i = 0, cur = 0; i + 1 < cnt; ++i) {
        cur += mo[i].weight;
        if (cur == 0) {
          ans = std::max(ans, mo[i + 1].value - mo[i].value);
        }
      }
    
      std::cout << ans << std::endl;
      return 0;
    }
    
  • 相关阅读:
    axios express设置跨域允许传递cookie
    yarn常用命令指北
    Web代理工具NProxy
    DevOps的了解
    css图片hover放大
    autoprefixer
    谈谈浏览器http缓存
    欢迎使用 MWeb
    优化关键渲染路径CRP
    chrome 61 更新
  • 原文地址:https://www.cnblogs.com/P6174/p/8268061.html
Copyright © 2011-2022 走看看