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的更多相关文章

  1. CodeForces 373B Making Sequences is Fun

    Making Sequences is Fun Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  2. Educational Codeforces Round 48 (Rated for Div. 2)

    http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法   为什么我做了那么多讨论,原 ...

  3. 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  ...

  4. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

  5. Codeforces Round #297 (Div. 2) [ 折半 + 三进制状压 + map ]

    传送门 E. Anya and Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. CF 1016 C —— 思路

    题目:http://codeforces.com/contest/1016/problem/C 一定是先蛇形走在回形走,所以预处理.暴力即可: 自己一开始写了一个,总是WA,又看了看TJ写法: 模仿一 ...

  7. Educational Codeforces Round 48 (Rated for Div. 2)异或思维

    题:https://codeforces.com/contest/1016/problem/D 题意:有一个 n * m 的矩阵, 现在给你 n 个数, 第 i 个数 a[ i ] 代表 i 这一行所 ...

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

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

  9. 【BZOJ 1016】【JSOI 2008】最小生成树计数

    http://www.lydsy.com/JudgeOnline/problem.php?id=1016 统计每一个边权在最小生成树中使用的次数,这个次数在任何一个最小生成树中都是固定的(归纳证明). ...

随机推荐

  1. JavaScript 条件判断算法综合实战

    在赌场21点游戏中,玩家可以通过计算牌桌上已经发放的卡牌的高低值来让自己在游戏中保持优势,这就叫21点算法. 根据下面的表格,每张卡牌都分配了一个值.如果卡牌的值大于0,那么玩家应该追加赌注.反之,追 ...

  2. oracle 12.2 linux/solaris正式发布

    oracle 12.2 linux/solaris正式发布,可以从http://www.oracle.com/technetwork/database/enterprise-edition/downl ...

  3. Python3 解析XML 层序遍历二叉树

    Python3 解析XML 层序遍历二叉树 keyword : python3, xml, xml.dom.minidom, 层序遍历, 层次遍历, 二叉树 part1 问题描述 面对如下 XML 文 ...

  4. opencv学习之路(7)、访问图像像素

    一.动态地址访问 #include <opencv2/opencv.hpp> #include<iostream> using namespace cv; using name ...

  5. bzoj 3237 连通图 - 并查集 - 线段树

    Input Output Sample Input 4 5 1 2 2 3 3 4 4 1 2 4 3 1 5 2 2 3 2 1 2 Sample Output Connected Disconne ...

  6. 【python003-变量】

    变量 一.在使用变量之前,需要先对其进行赋值 二.变量命名的规则:可以包含字母,数字,下划线,但是不能以数字开头 三.字符串: 1.引号内的一切东西 2.python的字符串是要在两边加上引号,对于单 ...

  7. Python3基础 response.info 服务器返回的header信息

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. 再谈fedora下的音乐和视频播放器的安装

    rpm包就相当于windows下的exe,已经是编译后的二进制代码,可以使用rpm命令或dnf install ???.rpm来安装 lnux下软件的安装跟windows不同, 后者要到处去找, 要做 ...

  9. MySql 语句收集

    目录 =与:=区别 序列号: 分组: 子查询分组: 同数据库表数据迁移 存储过程 参考: =与:=区别 = 只有在set和update时才是和:=一样,赋值的作用,其它都是等于的作用.鉴于此,用变量实 ...

  10. C# DateTime判断时间

    两种情况: 1 DateTime? dtTemp = null; if(dtTime != null) { //wawawa } 刚刚学会的,可空值类型,可判断是否赋值 2 DateTime dtTe ...