Codeforces 793C Mice Problem 几何(模拟)
来源:互联网 发布:mac怎么更改u盘格式 编辑:程序博客网 时间:2024/06/05 15:12
点击打开链接
题意:n个点(x,y),速度(vx,vy),n<=1e5,问n个点第一次同时落在矩形内时间?
某个点落在矩形内的时间t为:x1<=x+t1*vx<=x2,(x1-x)/vx<=t1<=(x2-x)/vx,y1<=y+t2*vy<=y2 (y1-y)/vy<=t2<=(y2-y)/vymax(t1,t2)<=t<=min(t1,t2) 每个点落在矩形内的时间看成一条线段,则求n条线段公共部分的左端点即可
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<ll,ll> ii;const int N=1e3+20;const int inf=2e8;const double eps=1e-11;int n;int main(){double x1,y1,x2,y2;double x,y,vx,vy;double L=0,R=1e9;while(cin>>n){bool flag=true;scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);for(int i=0;i<n;i++){double lx,rx,ly,ry,l,r;scanf("%lf%lf%lf%lf",&x,&y,&vx,&vy);if(vx==0)lx=0,rx=(x>x1&&x<x2)?inf:-1;else{lx=(x1-x)/vx,rx=(x2-x)/vx;if(vx<0)swap(lx,rx);}if(vy==0)ly=0,ry=(y>y1&&y<y2)?inf:-1;else{ly=(y1-y)/vy,ry=(y2-y)/vy;if(vy<0)swap(ly,ry);}if(ly>ry||lx>rx)flag=false;//else{l=max(lx,ly);r=min(rx,ry);//l<=t<=rL=max(l,L);R=min(r,R);}if(L>R)flag=false;}if(R-L>=eps&&flag)printf("%.10lf\n",L);elseputs("-1");}return 0;}
阅读全文
0 0
- Codeforces 793C Mice Problem 几何(模拟)
- 793C Mice problem
- codeforces 2C Commentator problem (1)-- 几何
- 【Codeforces Beta Round 2C】【计算几何 转化 模拟退火】Commentator problem 求一个点,使得该点到三个圆的视角范围尽可能接近
- codeforces 2 C. Commentator problem(模拟退火)
- codeforces 2C Commentator problem (2) -- 模拟退火
- Codeforces Beta Round #2 2C Commentator problem(模拟退火)
- CF-Tinkoff Challenge-Elimination Round-C-Mice problem
- Bag of mice CodeForces
- Codeforces CROC problem C
- [Codeforces]C. Commentator problem
- Codeforces Problem 332C
- CodeForces 1C(计算几何)
- codeforces 1C 计算几何
- CodeForces 382C【模拟】
- Codeforces 749C【模拟】
- CodeForces 118C 【模拟】
- Codeforces 863C 模拟
- 数据结构 跳表SkipList的原理和代码实现
- Spark Basic RDD 操作示例
- springMVC实现文件上传 删除 下载
- 每段时间Android开发10个知道(基础系列)-170526
- Tensorflow编写过程中遇到的各种小问题汇总
- Codeforces 793C Mice Problem 几何(模拟)
- logj
- iwconfig连接WiFi 热点上网
- Java Scanner 类
- Linux禁止ping以及开启ping的方法
- WebView加载服务器返回的html数据
- android自定义view之加载动画ColorBall
- Linux利用信号量实现线程的同步与互斥
- 小程序