题目

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2674

题意

有严格下降的n条线段,长度都为w,第i条线段起点xi,终点xi + w,高度yi,现在有s种垂直恒定速度可以选择,水平速度不能超过vh,问要经过每条线段,垂直恒定速度最大可以选择什么

思路

明显,二分枚举速度speed

第一条线段因为是起点所以肯定都能到达

对于第i条线段,从第i-1条线段出发落到i条线段相同高度所用时间为t = (yi - y_{i - 1}) / speed,设能到达的区域为[xlefttruei, xrighttruei],能到达的区域为[xlefttrue_{i-1}- vh * t, xrighttrue_{i-1} + vh * t]与自身线段[xi, xi + w]的交集,如果不存在这个交集,就代表落不到这个线段上。

感想:

现在uva无法通过,包括他人题解注明已通过的也不行

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
const int MAXN = 1e5 + ;
const int MAXS = 1e6 + ;
long long xleft[MAXN];
long long y[MAXN];
long long w, vh;
int n, s;
long long xlefttrue[MAXN], xrighttrue[MAXN];
int speeds[MAXS];
bool check(int speed) {
xlefttrue[] = xleft[] * speed;
xrighttrue[] = (xleft[] + w) * speed;
for (int i = ; i < n; i++) {
long long t = (y[i] - y[i - ]);
xlefttrue[i] = max(xleft[i] * speed, xlefttrue[i - ] - t * vh);
xrighttrue[i] = min((xleft[i] + w) * speed, xrighttrue[i - ] + t * vh);
if (xlefttrue[i] > xrighttrue[i])return false;
}
return true;
} int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int T;
cin >> T;
for (int ti = ;ti <= T; ti++) {
cin >> w >> vh >> n;
for (int i = ; i < n; i++) {
cin >> xleft[i] >> y[i];
}
cin >> s;
for (int i = ; i < s; i++) {
cin >> speeds[i];
}
sort(speeds, speeds + s);
int lind = , rind = s;
if (!check(speeds[lind]))cout << "IMPOSSIBLE" <<endl;
else {
while (lind < rind) {
int mid = (lind + rind) >> ;
if (mid == lind)break;
if (check(speeds[mid])) {
lind = mid;
}
else {
rind = mid;
}
}
cout << speeds[lind] << endl;
}
} return ;
}

UVa 11627 - Slalom 二分. oj错误题目 难度: 0的更多相关文章

  1. HDU 3076 ssworld VS DDD 概率dp,无穷级数,oj错误题目 难度:2

    http://acm.hdu.edu.cn/showproblem.php?pid=3076 不可思议的题目,总之血量越少胜率越高,所以读取时把两人的血量交换一下 明显每一轮的胜率和负率都是固定的,所 ...

  2. UVA 11627 Slalom(二分)

    二分,判断的时候,一个点一个点的考虑肯定是不行啦,考虑的单位是一个区间, 每次左端点尽量向左边移动,右端点尽量向右,得到下次可以达到的范围,检查一下和下一个区间有没有交集. #include<b ...

  3. ZOJ 3521 Fairy Wars oj错误题目,计算几何,尺取法,排序二叉树,并查集 难度:2

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3521 ATTENTION:如果用long long 减小误差,这道题只能用 ...

  4. UVa 11636 - Hello World! 二分,水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  5. UVa 11134 - Fabled Rooks 优先队列,贪心 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  6. UVa 10340 - All in All 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  7. UVa 3602 - DNA Consensus String 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  8. UVa LA 3213 - Ancient Cipher 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  9. OJ提交题目中的语言选项里G++与C++的区别

    一.OJ提交题目中的语言选项里G++与C++的区别 http://www.th7.cn/Program/cp/201405/199001.shtml 首先更正一个概念,C++是一门计算机编程语言,G+ ...

随机推荐

  1. python安装simplejson

    import simplejson 报错:ImportError: No module named simplejson simplejson是ansible一个很重要的依赖,经测试在python 2 ...

  2. flask中单选、多选、下拉框的获取

    1.单选: source = request.form.get('source') 2.多选:   joy = request.form.getlist('joy')    或者   joy = re ...

  3. Python3.0以上版本在对比图片相似中的应用

    首先声明一下,代码是从网上找到的,只是本人作以简单的修改. 请大家尊重原创. 我本地用到的是 Python 3.4   以及 Pillow (4.0.0)  第三方包. 方法一. #!/usr/bin ...

  4. codeforces 982B Bus of Characters

    题意: 有n排座位,每排有两个座位,每排座位的宽度都不一样. 有2 * n个人要上车,如果是内向的人,那么它会选择一排两个都是空位并且宽度最小的一排去坐: 如果是外向的人,会选择一排座位已经有人坐的, ...

  5. Java访问修饰符(访问控制符)

    Java 通过修饰符来控制类.属性和方法的访问权限和其他功能,通常放在语句的最前端.例如: public class className { // body of class } private bo ...

  6. linux系统(rpm与deb环境),JAVA JDK的配置

    步骤一:(配置 JAVA JDK  DEB系列linux系统) 1,下载JAVA JDK 1.1.官网下载java JDK (最好为1.7及以上版本) 下载地址http://www.oracle.co ...

  7. windows下python操作mysql模块安装

    百度教程说安装 pip install mysqldb 这在我的电脑上安装失败: Could not find a version that satisfies the requirement mys ...

  8. JavaScript Dom 查找

    JavaScript Dom 查找 一.直接查找 获取单个元素 document.getElementById('i1') 获取多个元素(列表数组) document.getElementsByTag ...

  9. 了解C语言

    初学时的程序都需要打#include<stdio.h>及int main()  //int main中int 声明函数类型为整形,main为主函数:‘//’为注释的意思,后面的内容不会运行 ...

  10. Odd Gnome【枚举】

    问题 I: Odd Gnome 时间限制: 1 Sec  内存限制: 128 MB 提交: 234  解决: 144 [提交] [状态] [命题人:admin] 题目描述 According to t ...