传送门

题意

给出一个矩形的左下角和右上角的坐标,给出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. 一份关于webpack2和模块打包的新手指南(一)

    webpack已成为现代Web开发中最重要的工具之一.它是一个用于JavaScript的模块打包工具,但是它也可以转换所有的前端资源,例如HTML和CSS,甚至是图片.它可以让你更好地控制应用程序所产 ...

  2. webstorm js版本设置被重置

    在下列路径下搜索ECMAScript,将版本号全部改为6 C:\Users\admin\.WebStorm2016.1\config\options\statistics.application.us ...

  3. 【TFS 2017 CI/CD系列 - 03】-- Release篇

    为Project创建Release必须要先创建Build,若还没有Build definition请看上一篇文章:[TFS 2017 CI/CD系列 - 02]-- Build篇 一.创建Releas ...

  4. 鸟哥的Linux私房菜-----13、账号管理

  5. 数据结构与算法问题 AVL二叉平衡树

    AVL树是带有平衡条件的二叉查找树. 这个平衡条件必须保持,并且它必须保证树的深度是O(logN). 一棵AVL树是其每一个节点的左子树和右子树的高度最多差1的二叉查找树. (空树的高度定义为-1). ...

  6. TestNg的工厂測试引用@DataProvider数据源----灵活使用工厂測试

    之前说过@Factory更适合于同一类型的參数变化性的測试,那么假设參数值没有特定的规律时,我们能够採用@Factory和@DataProvider相结合的方式进行測试 注意要点:请注意測试方法将被一 ...

  7. 阿里云Ubuntu部署java web(1) - 系统配置

    系统版本号:ubuntu 12.04 64位 ssh链接服务器(使用终端远程链接): ssh -l username IP地址 假设出现相似例如以下错误: @    WARNING: REMOTE H ...

  8. CodeForces 300C Beautiful Numbers(乘法逆元/费马小定理+组合数公式+高速幂)

    C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. 【iOS系列】-A server with the specified hostname could not be found.问题解决

    [iOS系列]-A server with the specified hostname could not be found.问题解决 Reveal 在iOS开发中可以方便查看界面的布局,较为方便的 ...

  10. Receiver type ‘X’ for instance message is a forward declaration

    这往往是引用的问题. ARC要求完整的前向引用,也就是说在MRC时代可能仅仅须要在.h中申明@class就能够,可是在ARC中假设调用某个子类中未覆盖的父类中的方法的话.必须对父类.h引用,否则无法编 ...