Codeforces 1016 E - Rest In The Shades
思路:
相似

红色的长度等于(y - s) / y 倍的 A' 和 B' 之间的 fence的长度
A' 是 p 和 A 连线和 x 轴交点, B'同理
交点也可以用相似求,然后lower_bound找到交点在哪里,然后通过预处理的fence长度的前缀和就可以求了,处理好边界
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);
//head const int N = 2e5 + ;
pdd f[N];
double sum[N];
int main() {
int n, q, l, r;
double s, a, b, x, y;
scanf("%lf %lf %lf", &s, &a, &b);
scanf("%d", &n);
for (int i = ; i <= n; i++) scanf("%lf %lf", &f[i].fi, &f[i].se);
sum[] = ;
for (int i = ; i <= n; i++) {
sum[i] = sum[i-] + f[i].se - f[i].fi;
}
scanf("%d", &q);
while(q--) {
scanf("%lf %lf", &x, &y);
double c1 = (a*y - s*x)/(y - s);
double c2 = (b*y - s*x)/(y - s);
int t = lower_bound(f+, f+n+, pdd(c1, )) - f;
double ans = ;
if(t == ) l = ;
else {
l = t;
if(c1 < f[t-].se) ans += f[t-].se - c1;
}
int tt = lower_bound(f+, f+n+, pdd(c2, )) - f;
if(tt == ) r = tt-;
else {
r = tt-;
if(c2 < f[tt-].se) ans -= f[tt-].se - c2;
}
if(r >= l) ans += sum[r] - sum[l-];
printf("%.10f\n", ans * (y - s) / y);
}
return ;
}
Codeforces 1016 E - Rest In The Shades的更多相关文章
- CodeForces 373B Making Sequences is Fun
Making Sequences is Fun Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- Educational Codeforces Round 48 (Rated for Div. 2)
http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法 为什么我做了那么多讨论,原 ...
- Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索
Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
- Codeforces Round #297 (Div. 2) [ 折半 + 三进制状压 + map ]
传送门 E. Anya and Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- CF 1016 C —— 思路
题目:http://codeforces.com/contest/1016/problem/C 一定是先蛇形走在回形走,所以预处理.暴力即可: 自己一开始写了一个,总是WA,又看了看TJ写法: 模仿一 ...
- Educational Codeforces Round 48 (Rated for Div. 2)异或思维
题:https://codeforces.com/contest/1016/problem/D 题意:有一个 n * m 的矩阵, 现在给你 n 个数, 第 i 个数 a[ i ] 代表 i 这一行所 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【BZOJ 1016】【JSOI 2008】最小生成树计数
http://www.lydsy.com/JudgeOnline/problem.php?id=1016 统计每一个边权在最小生成树中使用的次数,这个次数在任何一个最小生成树中都是固定的(归纳证明). ...
随机推荐
- centos7.3安装MongoDB
安装步骤: 1.配置包管理系统 vim /etc/yum.repos.d/mongodb.repo [mongodb] name=MongoDB Repository baseurl=http://d ...
- tcp编程 示例
#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <net ...
- Android之电话拨号和短信
拨打电话号码,需要添加权限设置,在安装的应用程序信息中可以看到此权限信息Intent doSth=new Intent();//意图:你想做什么呢?doSth.setAction(Intent.ACT ...
- 类中函数前、后、参数加const
1.参数加const:int fun(const int a) a在函数里不可被修改 2.函数前加const:const int* const fun() 这种一般是返回的指针或者是引用,加const ...
- Bootstrap3基础 disabled 多选框 鼠标放在方框与文字上都出现禁止 标识
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- Django框架(六) Django之模板继承
模版导入和继承 模版导入 一个页面只能继承一个模板,如何解决了?如何使用多个模板,或者引入其他页面 <% include "a.html" %> 可以引用多次 模板,i ...
- Ubuntu18.04 一些好用的扩展
原文:https://www.lulinux.com/archives/2589 一些好用的扩展: United:https://www.gnome-look.org/p/1167950/ dynam ...
- 為什麼gnome-terminal中不能使用ctrl_shift_f來進行查找? 是因為 跟输入法的全局设置衝突了!
但是,也要注意, 为什么ctrl+shift_f有时候可以使用, 有时候又不可以使用? 是因为, 这个跟输入法的状态有关, 如果输入法是英文, 那么中文的 "简体/繁体切换快捷键ctrl+s ...
- 再谈 linux 的sed用法
很多东西, 如果太复杂, 太庞杂, 一开始, 可以只掌握最简单的. 如果连最简单的都不能掌握, 那看那么多有什么用? 关于cut, sed的 处理过程和思想? vm: virtual machine, ...
- [NOI1995]石子合并 四边形不等式优化
链接 https://www.luogu.org/problemnew/show/P1880 思路 总之就是很牛逼的四边形不等式优化 复杂度\(O(n^2)\) 代码 #include <ios ...