题目

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. ionic 需要注意的知识点

  2. android studio java: -source 1.6 中不支持 switch 中存在字符串 的错误

    F4打开open moudle setting 将source Compatibility 改为1.7 F4打开open moudle setting 将targetCompatibility 改为1 ...

  3. Network In Network学习笔记

    Network In Network学习笔记 原文地址:http://blog.csdn.net/hjimce/article/details/50458190 作者:hjimce 一.相关理论 本篇 ...

  4. spring internalTransactionAdvisor 事务 advisor 初始化过程

    spring internalTransactionAdvisor 事务 advisor 初始化过程:

  5. k-means算法 - 数据挖掘算法(5)

    (2017-05-02 银河统计) k-means算法,也被称为k-平均或k-均值,是数据挖掘技术中一种广泛使用的聚类算法. 它是将各个聚类子集内的所有数据样本的均值作为该聚类的代表点,算法的主要思想 ...

  6. JAVA值传递之基本数据类型和引用数据类型

    #1.基本数据类型值传递 package 经典小Demo.值传递; public class Test { public static void main(String[] args) { int a ...

  7. 2015全国大学生数学建模B题浅谈

    题目请自主上网获取. 分析下思路.第一问,不同时空的出租车的“供求匹配”程度. 也就是说要选取的数据要有时间和地理两个维度.实体对象是出租车.关键的问题就是地点怎么选? 选择的城市具备如下经济较发达, ...

  8. [C++ Primer Plus] 第4章、复合类型(二)课后习题

    1.编写一个 c++ 程序,如下述输出示例所示的那样请求并显示信息 : What is your first name? Betty SueWhat is your last name? YeweWh ...

  9. 剑指offer(48)不用加减乘除做加法

    题目描述 写一个函数,求两个整数之和,要求在函数体内不得使用+.-.*./四则运算符号. 题目分析 不用加减乘除做加法,我第一时间想到的就是用位运算,毕竟计算机是二进制的,所有的操作都是以位运算为基础 ...

  10. i.MX6UL -- PWM用户空间使用方法【转】

    本文转载自:https://blog.csdn.net/u014486599/article/details/53010114 i.MX6UL -- PWM用户空间使用方法 开发平台: 珠海鼎芯D51 ...