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 ...
随机推荐
- 没啥用,更换注册表信息使webbrower选择适合的版本
/// <summary> /// 修改注册表信息来兼容当前程序 /// /// </summary> ...
- Ubuntu 16.04安装双显卡驱动方法收集
说明:不一定有效,要不断尝试. http://www.linuxwang.com/html/2150.html http://blog.csdn.net/feishicheng/article/det ...
- Deepin-我为什么推荐它!
针对Win上的开发软件,大部分都需要密匙或者破解,而Deepin不敢说一应俱全,但全沾边是没问题的 无论是编程.娱乐还是其它的,基本上都可以做到,而且它还应用了Crossover来兼容大部分的Win软 ...
- python手记(53)
import sys import pygame from pygame.locals import * import time import math pygame.init() screen=py ...
- CentOS 使用httpd 配置局域网 yum源
1.上传centos iso而且挂载 mkdir /mnt/cdr/iso mount -o /xxx.iso /mnt/cdr 2.使用createrepo来创建repo文件 cd /mnt/cdr ...
- Ubuntu14.04 64bit下Caffe + CUDA 6.5安装详细步骤
不多说,直接上干货! 笔者花了很长时间才装完,主要是cuda安装和opencv安装比较费劲,cuda找不到32位的安装包只好重装64位的ubuntu系统,opencv 也是尝试了很久才解决,这里建议用 ...
- 【HDOJ 3652】B-number
[HDOJ 3652]B-number 给一整数n 找<=n的整数中能被13整除且含有13的 数位dp 记忆化! . 一入记忆化深似海. ..再也不想用递推了...发现真的非常好想 仅仅要保证满 ...
- Virtual IP address
https://en.wikipedia.org/wiki/Virtual_IP_address Virtual IP address From Wikipedia, the free encyclo ...
- 第一个Java程序示例——Hello World!【转】
本文转载自: 跟随世界潮流,第一个Java程序输出“Hell World!”. 通过Eclipse运行程序 启动Eclipse,在菜单中选择“文件 --> 新建 --> Java项目”,弹 ...
- YTU 2405: C语言习题 牛顿迭代法求根
2405: C语言习题 牛顿迭代法求根 时间限制: 1 Sec 内存限制: 128 MB 提交: 562 解决: 317 题目描述 用牛顿迭代法求根.方程为ax3+bx2+cx+d=0.系数a,b ...