传送门

题意

给出一个矩形的左下角和右上角的坐标,给出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. BOOST asio 例程daytime不使用库编译方法

    在不使用lib库编译daytime client程序时,按照<Boost程序库完全开发指南>添加的定义 #define BOOST_REGEX_NO_LIB#define BOOST_DA ...

  2. 蓝桥杯 算法提高 金属采集 [ 树形dp 经典 ]

    传送门 算法提高 金属采集 时间限制:1.0s   内存限制:256.0MB     锦囊1   锦囊2   锦囊3   问题描述 人类在火星上发现了一种新的金属!这些金属分布在一些奇怪的地方,不妨叫 ...

  3. msp430入门编程47

    msp430中C语言的人机交互--菜单退出 msp430入门编程 msp430入门学习

  4. Distinct Subsequences (dp)

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  5. 代理服务器squid简介

    Squid 是一个高性能.开源的代理缓存服务器和 Web 缓存进程,支持 FTP.Internet Gopher.HTTPS 和 SSL 等多种协议.它通过一个非阻塞的.I/O 事件驱动的单一进程处理 ...

  6. 利用Druid实现应用和SQL监控

    一.关于Druid Druid是一个JDBC组件,它包括三部分: DruidDriver 代理Driver,能够提供基于Filter-Chain模式的插件体系. DruidDataSource 高效可 ...

  7. iOS中MRC和ARC混编

    1. 在targets的build phases选项下Compile Sources下选择,不使用arc编译的文件.双击它.输入 -fno-objc-arc 就可以(这个类就能够使用MRC模式) 2. ...

  8. Android中个人推崇的数据库使用方式

    手机应用开发中常常会使用到数据库存储一些资料或者进行数据缓存,android中为我们提供了一个轻量的数据库.在上层进行了一层封装,同一时候还为我们提供了ContentProvider的框架.方便我们进 ...

  9. Android KK后为何工厂模式下无法adb 无法重新启动机器 ?

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  10. Fix "Unable to lock the administration directory (/var/lib/dpkg/)" in Ubuntu

    While using the apt-get command or the relatively new APT package management tool in Ubuntu Linux or ...