题目连接:http://codeforces.com/contest/832/problem/C

C. Strange Radiation
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed.

You can put a bomb in some point with non-negative integer coordinate, and blow it up. At this moment all people will start running with their maximum speed in the direction they are facing. Also, two strange rays will start propagating from the bomb with speed s: one to the right, and one to the left. Of course, the speed s is strictly greater than people's maximum speed.

The rays are strange because if at any moment the position and the direction of movement of some ray and some person coincide, then the speed of the person immediately increases by the speed of the ray.

You need to place the bomb is such a point that the minimum time moment in which there is a person that has run through point 0, and there is a person that has run through point 106, is as small as possible. In other words, find the minimum time moment t such that there is a point you can place the bomb to so that at time moment t some person has run through 0, and some person has run through point106.

Input

The first line contains two integers n and s (2 ≤ n ≤ 105, 2 ≤ s ≤ 106) — the number of people and the rays' speed.

The next n lines contain the description of people. The i-th of these lines contains three integers xivi and ti (0 < xi < 106, 1 ≤ vi < s,1 ≤ ti ≤ 2) — the coordinate of the i-th person on the line, his maximum speed and the direction he will run to (1 is to the left, i.e. in the direction of coordinate decrease, 2 is to the right, i.e. in the direction of coordinate increase), respectively.

It is guaranteed that the points 0 and 106 will be reached independently of the bomb's position.

Output

Print the minimum time needed for both points 0 and 106 to be reached.

Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Namely, if your answer is a, and the jury's answer is b, then your answer is accepted, if .

Examples
input
2 999
400000 1 2
500000 1 1
output
500000.000000000000000000000000000000
input
2 1000
400000 500 1
600000 500 2
output
400.000000000000000000000000000000
Note

In the first example, it is optimal to place the bomb at a point with a coordinate of 400000. Then at time 0, the speed of the first person becomes 1000 and he reaches the point 106 at the time 600. The bomb will not affect on the second person, and he will reach the 0point at the time 500000.

In the second example, it is optimal to place the bomb at the point 500000. The rays will catch up with both people at the time 200. At this time moment, the first is at the point with a coordinate of 300000, and the second is at the point with a coordinate of 700000. Their speed will become 1500 and at the time 400 they will simultaneously run through points 0 and 106.

题意:改出N个人的初始始方向和速度,然后让你放一颗炸弹在某个整数位置,炸弹会在最开始爆炸,并且造成往左往右的两个光束,当光束追上人(有相同的方向)的时候人会加上光的速度,问你把炸弹放在某一个位置使得在往左往右都跑出至少一人的时间?

题解:二分时间,每次判断能否在规定时间能否左右都跑出至少一人,

#include<bits/stdc++.h>
#include<algorithm>
using namespace std ;
typedef long long ll;
const int maxn=1e5+;
int s,n;
struct node
{
int p,v,f;
}a[maxn];
bool judge(double lim)
{
bool left=false,right=false;
double left_l=1e6,left_r=,right_l=1e6,right_r=;
for(int i=;i<n;i++)
{
if(a[i].f==)
{
if(a[i].p-(s+a[i].v)*lim>)continue;
left=true;
if(a[i].p-a[i].v*lim<=0.0)
{
left_l=;left_r=1e6;
continue;
}
double rr=floor((s-a[i].v)*(((a[i].v+s)*lim-a[i].p)/(double)s)+a[i].p);//解三元一次方程就可以得到最大位置
left_r=max(left_r,rr);
left_l=min(left_l,(double)a[i].p);
}
else
{
if(a[i].p+(s+a[i].v)*lim<1e6)continue;
right=true;
if(a[i].p+a[i].v*lim>=1e6)
{
right_l=,right_r=1e6;
continue;
}
double LL=ceil(a[i].p+(a[i].v-s)*(1e6-a[i].p-(a[i].v+s)*lim)/(-s));//同上
right_l=min(right_l,LL);
right_r=max(right_r,(double)a[i].p);
}
}
if(!left||!right)return false;
if((left_l>left_r)||(right_l>right_r))
return false;
if(right_r<left_l||right_l>left_r)return false;
else return true;
}
int main()
{
scanf("%d %d",&n,&s);
for(int i=;i<n;i++)
{
scanf("%d %d %d",&a[i].p,&a[i].v,&a[i].f);
}
double l=0.0,r=1e6,mid;
for(int i=;i<=;i++)
{
mid=(l+r)/;
if(judge(mid))
{
r=mid;
}
else
{
l=mid;
}
}
printf("%.12f\n",r);
}

Codeforces Round #425 (Div. 2)C的更多相关文章

  1. Codeforces Round #425 (Div. 2)

    A 题意:给你n根棍子,两个人每次拿m根你,你先拿,如果该谁拿的时候棍子数<m,这人就输,对手就赢,问你第一个拿的人能赢吗 代码: #include<stdio.h>#define ...

  2. Codeforces Round #425 (Div. 2) Problem D Misha, Grisha and Underground (Codeforces 832D) - 树链剖分 - 树状数组

    Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations ...

  3. Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论

    n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...

  4. Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力

    It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...

  5. Codeforces Round #425 (Div. 2) Problem A Sasha and Sticks (Codeforces 832A)

    It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day h ...

  6. Codeforces Round #425 (Div. 2) B. Petya and Exam(字符串模拟 水)

    题目链接:http://codeforces.com/contest/832/problem/B B. Petya and Exam time limit per test 2 seconds mem ...

  7. Codeforces Round #425 (Div. 2))——A题&&B题&&D题

    A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...

  8. Codeforces Round #425 (Div. 2) B - Petya and Exam

    地址:http://codeforces.com/contest/832/problem/B 题目: B. Petya and Exam time limit per test 2 seconds m ...

  9. Codeforces Round #425 (Div. 2) C - Strange Radiation

    地址:http://codeforces.com/contest/832/problem/C 题目: C. Strange Radiation time limit per test 3 second ...

随机推荐

  1. [WPF]如何调试Data Binding

    前言 在WPF开发中,将ViewModel中对象绑定到UI上时,会出现明明已经将数据对象Binding到UI,但是UI上就是不显示等等的问题.这篇博客将介绍WPF Data Binding相关的内容, ...

  2. GeoServer初识与安装

    学习过程中发现官网上的东西足够基础了,所以在这只做一下索引和补充. 官方网址:http://live.osgeo.org/zh/overview/geoserver_overview.html 安装: ...

  3. C#多线程的用法7-线程间的协作ManualResetEvent

    ManualResetEvent:手动重置事件,它用于线程间同步时用法非常简单也易于理解. private static void MultiThreadSynergicWithManualReset ...

  4. zbrush曲面增加厚度

    把曲面增加厚度方便雕刻机雕刻. 可以使用zbrush中的边循环功能. 1.准备好需要增加厚度的曲面,把曲面的边缘调整好,尽量的变得平滑. 2.将模型导入到zbrush中,开启双面显示,以方便观察模型的 ...

  5. Mock Server 入门

    Mock Server介绍 什么是mock ? 我在去年的时候介绍一篇幅 python mock的基本使用,http://www.cnblogs.com/fnng/p/5648247.html 主要是 ...

  6. 第4阶段——制作根文件系统之分析init进程(2)

    本节目标: (1) 了解busybox(init进程和命令都放在busybox中) (2) 创建SI工程,分析busybox源码来知道init进程做了哪些事情 (3)  分析busybox中init进 ...

  7. react 入门

    一:virtual DOM  虚拟DOM树 在React中,render执行的结果得到的并不是真正的DOM节点,结果仅仅是轻量级的JavaScript对象,我们称之为virtual DOM. 虚拟DO ...

  8. poj 1330 LCA最近公共祖先

    今天学LCA,先照一个模板学习代码,给一个离线算法,主要方法是并查集加上递归思想. 再搞,第一个离线算法是比较常用了,基本离线都用这种方法了,复杂度O(n+q).通过递归思想和并查集来寻找最近公共祖先 ...

  9. 全平台轻量级 Verilog 编译器 & 仿真环境

    一直苦于 modelsim 没有Mac版本,且其体量过大,在学习verilog 时不方便使用. 终于找到一组轻量级且全平台 ( Linux+Windows+macOS ) 的编译仿真工具组. Icar ...

  10. Web in Linux小笔记001

    Linux灾难恢复: Root密码修复 Centos single Filesystem是硬盘文件根目录,无法再cd ..就像macitosh 硬盘图标 Pwd:显示绝对路径 MBR修复 模拟MBR被 ...