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 统计每一个边权在最小生成树中使用的次数,这个次数在任何一个最小生成树中都是固定的(归纳证明). ...
随机推荐
- python之块包导入
一.模块 1.什么是模块 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编写 ...
- GDI的 点 线 面 双缓冲 位图的绘制
1.输出文本 // 输出文本 ,,)); //设置字体颜色,但最后都要返回原来的字体格式 COLORREF clrBackColor = SetBkColor(hDC, RGB(,,)); //设置背 ...
- 头像上传uploadPreview插件
原文链接:https://blog.csdn.net/Alisa_L/article/details/52923953 uploadPreview 今天写头像上传,使用到uploadPreview插件 ...
- 类中函数前、后、参数加const
1.参数加const:int fun(const int a) a在函数里不可被修改 2.函数前加const:const int* const fun() 这种一般是返回的指针或者是引用,加const ...
- ECharts公共组件:title详解、 tooltip详解、toolbox详解、legend详解、dataZoom详解、visualMap全解
1. Title mytextStyle={ color:"#333", //文字颜色 fontStyle:"norm ...
- Git rebase的使用
rebase 在 Git 中整合来自不同分支的修改主要有两种方法:merge 以及 rebase. 在本节中我们将学习什么是“rebase”,怎样使用“rebase”,并将展示该操作的惊艳之处,以及指 ...
- linux内核中的linuxPPS是什么?
答: linux每秒脉冲数(linux pulse per second),LinuxPPS 在系统中提供一个编程接口(API)去定义几个PPS源; 一个PPS源就是一个每秒能提供高精度信号的设备,以 ...
- 深入了解JVW
Java内存组成介绍:堆(Heap)和非堆(Non-heap)内存 按照官方的说法:“Java 虚拟机具有一个堆,堆是运行时数据区域,所有类实例和数组的内存均从此处分配.堆是在 Java 虚拟机启动时 ...
- UVALive 7501 Business Cycle(二分)题解
题意:n个数,有一个起始值,按顺序从第一个开始不断循环取数,如果取完后相加小于0就变为0,最多取p个数,问你得到大于等于值g所需要的最小起始值为多少 思路:这题目爆long long爆的毫无准备,到处 ...
- 给Ubuntu添加清华的软件源
找到 sources.list 文件 cd /etc/apt/ 编辑 vim sources.list 在最后面加上下面这几条语句 # 默认注释了源码镜像以提高 apt update 速度,如有需要可 ...