Tinkoff Challenge - Elimination Round C. Mice problem(模拟)
传送门
题意
给出一个矩形的左下角和右上角的坐标,给出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(模拟)的更多相关文章
- Tinkoff Challenge - Elimination Round D. Presents in Bankopolis(区间DP)
http://codeforces.com/contest/793/problem/D 题意:给出一些点和他们之间的距离,是有向的,这些点从1~n顺序排列,现在选出k个点组成一条路径,使他们之间的距离 ...
- Tinkoff Challenge - Elimination Round B. Igor and his way to work(dfs+优化)
http://codeforces.com/contest/793/problem/B 题意:一个地图,有起点和终点还有障碍点,求从起点出发到达终点,经过的路径上转弯次数是否能不超过2. 思路: 直接 ...
- Tinkoff Challenge - Elimination Round 开始补题
A. Oleg and shares time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 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 ...
- 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 ...
- 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 ...
- 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D
http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...
- 线段树 或者 并查集 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C
http://codeforces.com/contest/722/problem/C 题目大意:给你一个串,每次删除串中的一个pos,问剩下的串中,连续的最大和是多少. 思路一:正方向考虑问题,那么 ...
- 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 ...
随机推荐
- JAVA中json转换为集合(对象)之间的相互转换
字符串转换为json对象: String strResult = RestUtil.getRestContent(url+"/service/peccancy/myOrderList&quo ...
- [Bzoj2120]数颜色 (非正解 )(莫队)
2120: 数颜色 Time Limit: 6 Sec Memory Limit: 259 MBSubmit: 6286 Solved: 2489[Submit][Status][Discuss] ...
- loj6172 Samjia和大树(树形DP+找规律)
题目: https://loj.ac/problem/6172 分析: 首先容易得出这样的dp式子 然后发现后面那个Σ其实是两段区间,可以用总和减去中间一段区间表示,所以只要维护个前缀和就ok了 这样 ...
- IDEA添加作者注释
1.打开IDEA的settings,然后在Editor下找到File and Code Templates 2.然后选择File Header 选择需要注释的的格式即可.
- cors跨域深刻理解
1.跨域问题只出现在前端和后端不在同一个主机上.前后端在同一个主机上不会出现跨域问题. 2.浏览器的一种自我保护机制,不允许出现本地浏览器ajax异步请求访问127.0.0.1以外的系统,因为浏览器不 ...
- Node.js开发Web后台服务(转载)
原文:http://www.cnblogs.com/best/p/6204116.html 目录 一.简介 二.搭建Node.js开发环境 2.1.安装Node.js 2.2.安装IDE开发Node. ...
- CentOS里route命令详解
Route 功能简述:linux系统中的route命令能够用于IP路由表的显示和操作.它的主要作用是创建一个静态路由让指定一个主机或者一个网络通过一个网络接口,如eth0.当使用"add&q ...
- 鼠标放上去Div旋转特效代码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- win8系统 如何不显示这台电脑的文件夹
在win8系统中,默认有下面这种文件夹 只要打开注册表编辑器,找到下面所示的项目,删除所有子文件夹即可(最后剩下一个DelegateFolders不用管) [HKEY_LOCAL_MACHINE\ ...
- 吉哥系列故事——完美队形II(hdu4513+Manacher)
吉哥系列故事--完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) T ...