Codeforces 989D A Shade of Moonlight
列列式子发现, 对于同一个云来说只有反向的云才能和它相交, 然后我们发现这个东西有单调性,然后二分就好啦。
- #include<bits/stdc++.h>
- #define LL long long
- #define fi first
- #define se second
- #define mk make_pair
- #define PLL pair<LL, LL>
- #define PLI pair<LL, int>
- #define PII pair<int, int>
- #define SZ(x) ((int)x.size())
- #define ull unsigned long long
- using namespace std;
- const int N = 1e5 + ;
- const int inf = 0x3f3f3f3f;
- const LL INF = 0x3f3f3f3f3f3f3f3f;
- const int mod = 1e9 + ;
- const double eps = 1e-;
- const double PI = acos(-);
- int n, l, w;
- vector<int> a;
- vector<int> b;
- bool check(int x1, int x2) {
- return abs(x1 + x2 + l) < 1LL * (x2 + l - x1) * w;
- }
- int main() {
- scanf("%d%d%d", &n, &l, &w);
- for(int i = ; i <= n; i++) {
- int x, v; scanf("%d%d", &x, &v);
- if(v == ) a.push_back(x);
- else b.push_back(x);
- }
- LL ans = ;
- sort(a.begin(), a.end());
- sort(b.begin(), b.end());
- for(auto& x2 : b) {
- int low = ;
- int high = lower_bound(a.begin(), a.end(), x2) - a.begin() - ;
- int p = -;
- while(low <= high) {
- int mid = (low + high) >> ;
- if(check(a[mid], x2)) p = mid, low = mid + ;
- else high = mid - ;
- }
- ans += p + ;
- }
- printf("%lld\n", ans);
- return ;
- }
- /*
- */
Codeforces 989D A Shade of Moonlight的更多相关文章
- A Shade of Moonlight CodeForces - 989D
看这位博主的吧:https://blog.csdn.net/Steaunk/article/details/80660954
- *Codeforces989D. A Shade of Moonlight
数轴上$n \leq 100000$个不重叠的云,给坐标,长度都是$l$,有些云速度1,有些云速度-1,风速记为$w$,问在风速不大于$w_{max}$时,有几对云可能在0相遇.每一对云单独考虑. 多 ...
- 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 ...
- CodeForces 989D
题意略. 思路: 可以看成是所有的云彩照常运动,而月亮在跑.只要两个云彩相交后,在分离前月亮能赶到,就算是符合题意的. 可以知道,两个相隔越远的相向运动地云彩是越有可能符合题意的,因为它们相遇所用时间 ...
- codeforces 148D之概率DP
http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test 2 seconds memory l ...
- 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 ...
- 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 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- OpenStack实践系列⑤网络服务Neutron
OpenStack实践系列⑤网络服务Neutron 3.8 Neturn 服务部署 注册neutron服务 [root@node1 ~]# source admin-openrc.sh [root@n ...
- JS:判断是否是移动端
通过User-Agent判断 代码: if(navigator.userAgent.match(/mobile/i)) { //业务层代码 $('body').removeClass("si ...
- WINDOWS资源编译器出错信息
ACCELERATORS语句的type域应包含ASCⅡ值或VIRTKEY值. BEGIN expected in table BEGIN关键字应紧跟在ACCELERATOR ...
- CodeVs 3150 (大数 + 递推)
#include<iostream> #include<cstdio> #include<cstring> #include<string> #incl ...
- MySQL NULL处理
-- 首先在用户表中插入数据如下 TRUNCATE TABLE UserInfo ; INSERT INTO `userinfo`(`ID`,`UserName`,`UserLogin`,`User ...
- Java替换中使用正则表达式实现中间模糊匹配
使用“.+?”实现中间模糊匹配的代码: public class Test { public static void main(String[] args) { String str="总会 ...
- 洛谷P3317 [SDOI2014]重建 [Matrix-Tree定理]
传送门 思路 相信很多人像我一样想直接搞Matrix-Tree定理,而且还过了样例,然后交上去一分没有. 但不管怎样这还是对我们的思路有一定启发的. 用Matrix-Tree定理搞,求出的答案是 \[ ...
- LuoGu P1006 传纸条
题目传送门 这题嘛...方格取数和这题一样一样的 只不过这题是从左上到右下再回去罢了(来回一趟和来两趟有区别么?没有,那么这题和上题用一样的转移和状态就行了 没什么好说的,说一下我的错误好了: 人家图 ...
- PHP7运行环境搭建(Windows7)
注:本文来源于< PHP7运行环境搭建(Windows7) > php7号称能直追facebook的HHVM,为了体验一把传说中的高性能,我特意在本地电脑上尝试着安装了php7, ...
- Confluence 6 通过 SSL 或 HTTPS 运行 - 修改你 Confluence 的 server.xml 文件
下一步你需要配置 Confluence 来使用 HTTPS: 编辑 <install-directory>/conf/server.xml 文件. 取消注释下面的行: <Connec ...