A Shade of Moonlight

列列式子发现, 对于同一个云来说只有反向的云才能和它相交, 然后我们发现这个东西有单调性,然后二分就好啦。

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define fi first
  4. #define se second
  5. #define mk make_pair
  6. #define PLL pair<LL, LL>
  7. #define PLI pair<LL, int>
  8. #define PII pair<int, int>
  9. #define SZ(x) ((int)x.size())
  10. #define ull unsigned long long
  11.  
  12. using namespace std;
  13.  
  14. const int N = 1e5 + ;
  15. const int inf = 0x3f3f3f3f;
  16. const LL INF = 0x3f3f3f3f3f3f3f3f;
  17. const int mod = 1e9 + ;
  18. const double eps = 1e-;
  19. const double PI = acos(-);
  20.  
  21. int n, l, w;
  22. vector<int> a;
  23. vector<int> b;
  24.  
  25. bool check(int x1, int x2) {
  26. return abs(x1 + x2 + l) < 1LL * (x2 + l - x1) * w;
  27. }
  28.  
  29. int main() {
  30. scanf("%d%d%d", &n, &l, &w);
  31. for(int i = ; i <= n; i++) {
  32. int x, v; scanf("%d%d", &x, &v);
  33. if(v == ) a.push_back(x);
  34. else b.push_back(x);
  35. }
  36. LL ans = ;
  37. sort(a.begin(), a.end());
  38. sort(b.begin(), b.end());
  39. for(auto& x2 : b) {
  40. int low = ;
  41. int high = lower_bound(a.begin(), a.end(), x2) - a.begin() - ;
  42. int p = -;
  43. while(low <= high) {
  44. int mid = (low + high) >> ;
  45. if(check(a[mid], x2)) p = mid, low = mid + ;
  46. else high = mid - ;
  47. }
  48. ans += p + ;
  49. }
  50. printf("%lld\n", ans);
  51. return ;
  52. }
  53.  
  54. /*
  55. */

Codeforces 989D A Shade of Moonlight的更多相关文章

  1. A Shade of Moonlight CodeForces - 989D

    看这位博主的吧:https://blog.csdn.net/Steaunk/article/details/80660954

  2. *Codeforces989D. A Shade of Moonlight

    数轴上$n \leq 100000$个不重叠的云,给坐标,长度都是$l$,有些云速度1,有些云速度-1,风速记为$w$,问在风速不大于$w_{max}$时,有几对云可能在0相遇.每一对云单独考虑. 多 ...

  3. CF #487 (Div. 2) D. A Shade of Moonlight 构造_数形结合

    题意: 给 nnn个长度为 lll 且互不相交的开区间 (xi,xi+l)(x_{i}, x_{i}+l)(xi​,xi​+l) ,每个区间有一个移动速度 vvv,v∈1,−1v∈1,-1v∈1,−1 ...

  4. CodeForces 989D

    题意略. 思路: 可以看成是所有的云彩照常运动,而月亮在跑.只要两个云彩相交后,在分离前月亮能赶到,就算是符合题意的. 可以知道,两个相隔越远的相向运动地云彩是越有可能符合题意的,因为它们相遇所用时间 ...

  5. codeforces 148D之概率DP

    http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test 2 seconds memory l ...

  6. Codeforces Round #105 (Div. 2) D. Bag of mice 概率dp

    题目链接: http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test2 secondsmemo ...

  7. Codeforces 148 D Bag of mice

    D. Bag of mice http://codeforces.com/problemset/problem/148/D time limit per test 2 seconds memory l ...

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. OpenStack实践系列⑤网络服务Neutron

    OpenStack实践系列⑤网络服务Neutron 3.8 Neturn 服务部署 注册neutron服务 [root@node1 ~]# source admin-openrc.sh [root@n ...

  2. JS:判断是否是移动端

    通过User-Agent判断 代码: if(navigator.userAgent.match(/mobile/i)) { //业务层代码 $('body').removeClass("si ...

  3. WINDOWS资源编译器出错信息

    ACCELERATORS语句的type域应包含ASCⅡ值或VIRTKEY值.        BEGIN expected in table        BEGIN关键字应紧跟在ACCELERATOR ...

  4. CodeVs 3150 (大数 + 递推)

    #include<iostream> #include<cstdio> #include<cstring> #include<string> #incl ...

  5. MySQL NULL处理

    -- 首先在用户表中插入数据如下 TRUNCATE TABLE UserInfo ; INSERT  INTO `userinfo`(`ID`,`UserName`,`UserLogin`,`User ...

  6. Java替换中使用正则表达式实现中间模糊匹配

    使用“.+?”实现中间模糊匹配的代码: public class Test { public static void main(String[] args) { String str="总会 ...

  7. 洛谷P3317 [SDOI2014]重建 [Matrix-Tree定理]

    传送门 思路 相信很多人像我一样想直接搞Matrix-Tree定理,而且还过了样例,然后交上去一分没有. 但不管怎样这还是对我们的思路有一定启发的. 用Matrix-Tree定理搞,求出的答案是 \[ ...

  8. LuoGu P1006 传纸条

    题目传送门 这题嘛...方格取数和这题一样一样的 只不过这题是从左上到右下再回去罢了(来回一趟和来两趟有区别么?没有,那么这题和上题用一样的转移和状态就行了 没什么好说的,说一下我的错误好了: 人家图 ...

  9. PHP7运行环境搭建(Windows7)

    注:本文来源于<    PHP7运行环境搭建(Windows7)   > php7号称能直追facebook的HHVM,为了体验一把传说中的高性能,我特意在本地电脑上尝试着安装了php7, ...

  10. Confluence 6 通过 SSL 或 HTTPS 运行 - 修改你 Confluence 的 server.xml 文件

    下一步你需要配置 Confluence 来使用 HTTPS: 编辑 <install-directory>/conf/server.xml 文件. 取消注释下面的行: <Connec ...