传送门

题意

给出一个矩形的左下角和右上角的坐标,给出n个点的初始坐标和运动速度和方向,询问是否存在一个时间使得所有点都在矩形内,有则输出最短时间,否则输出-1

分析

对于每个点如果运动过程中都不在矩形内,输出-1

每个点的横纵运动分开考虑,判断处理得到点到达矩形边界的时间段,取交集,具体见代码

trick

1.all the mice that are strictly inside the mousetrap,即在矩形边界点不算入矩形

2.卡精度

代码

#include <bits/stdc++.h>
using namespace std; #define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
#pragma comment(linker, "/STACK:102400000,102400000")
inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}} int n;
double x1,y1,x2,y2,rx,ry,vx,vy,minn,maxn;
const double eps = 1e-13;
bool flag;
void work(double loc,double v,double l,double r)
{
if(fabs(v)<eps)
{
if((loc+eps)<=r&&(loc-eps)>=l) return ;
else { flag=1;return ; }
}
if(v<0)
{
l=-l,r=-r,v=-v,loc=-loc;
swap(l,r);
}
if(loc>r) { flag=1;return; }
minn=min(minn,(r-loc)/v);
if(loc<l) maxn=max(maxn,(l-loc)/v);
}
int main()
{
scanf("%d",&n);
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
minn=1e9,maxn=0;
for(int i=1;i<=n;++i)
{
scanf("%lf%lf%lf%lf",&rx,&ry,&vx,&vy);
if(flag) continue;
work(rx,vx,x1,x2);
work(ry,vy,y1,y2);
}
//printf("minn=%f maxn=%f\n",minn,maxn);
if(flag) { puts("-1");return 0; }
if(maxn+eps<=minn) printf("%f\n",maxn);else puts("-1");
}

Tinkoff Challenge - Elimination Round C. Mice problem(模拟)的更多相关文章

  1. Tinkoff Challenge - Elimination Round D. Presents in Bankopolis(区间DP)

    http://codeforces.com/contest/793/problem/D 题意:给出一些点和他们之间的距离,是有向的,这些点从1~n顺序排列,现在选出k个点组成一条路径,使他们之间的距离 ...

  2. Tinkoff Challenge - Elimination Round B. Igor and his way to work(dfs+优化)

    http://codeforces.com/contest/793/problem/B 题意:一个地图,有起点和终点还有障碍点,求从起点出发到达终点,经过的路径上转弯次数是否能不超过2. 思路: 直接 ...

  3. Tinkoff Challenge - Elimination Round 开始补题

    A. Oleg and shares time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列

    A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  5. Tinkoff Challenge - Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2) 继续跪一把

    这次的前三题挺简单的,可是我做的不快也不对. A. Bank Robbery time limit per test 2 seconds memory limit per test 256 megab ...

  6. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)(set容器里count函数以及加强for循环)

    题目链接:http://codeforces.com/contest/722/problem/D 1 #include <bits/stdc++.h> #include <iostr ...

  7. 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D

    http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...

  8. 线段树 或者 并查集 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C

    http://codeforces.com/contest/722/problem/C 题目大意:给你一个串,每次删除串中的一个pos,问剩下的串中,连续的最大和是多少. 思路一:正方向考虑问题,那么 ...

  9. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心

    D. Generating Sets 题目连接: http://codeforces.com/contest/722/problem/D Description You are given a set ...

随机推荐

  1. OC温习四:数组

    /** arrayByAddingObject -- 往数组A添加一个数据,返回一个数组的形式,即必须有一个数组来接受 */ NSArray *array = [NSArray arrayWithOb ...

  2. [Bzoj2286][Sdoi2011]消耗战(虚树模板题附讲解)

    2286: [Sdoi2011]消耗战 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 4896  Solved: 1824[Submit][Statu ...

  3. ATcoder 2000 Leftmost Ball

    Problem Statement Snuke loves colorful balls. He has a total of N×K balls, K in each of his favorite ...

  4. DotProject首页、文档和下载 - 项目管理工具 - 开源中国社区

    DotProject首页.文档和下载 - 项目管理工具 - 开源中国社区

  5. CSS 空中飘动的云动画

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. xml文件的schema也是经过jdk编译器编译的,如果xsd没引入完整,而xml中又用到了这些标签,就会编译不通过啊。

    1.xml文件的schema也是经过jdk编译器编译的,如果xsd没引入完整,而xml中又用到了这些标签,就会编译不通过啊. 2.java编译器会下载xsd的指定链接文件,加在代码里,一起编译

  7. 【algorithm】尾递归

    尾递归和一般的递归不同在对内存的占用,普通递归创建stack累积而后计算收缩,尾递归只会占用恒量的内存(和迭代一样).SICP中描述了一个内存占用曲线,用以上答案中的Python代码为例(普通递归): ...

  8. Unable to connect to database server to retrieve database list; Arcgis 连接不上postsql库;

    在C:\Program Files (x86)\ArcGIS\Desktop10.2\bin 目录下添加 pg依赖的插件 插件下载地址:

  9. Java中常见的排序算法

    这是我摘取的一段英文资料.我认为学习算法之前,对各种排序得有个大致的了解: Sorting algorithms are an important part of managing data. At ...

  10. 工作总结 js 选择器选择多条元素 支持一起设置他们属性 $("#edumes input[type='radio']").prop("checked", false);

    $("#edumes input[type='radio']").prop("checked", false); $("#edumes input[t ...