poj 1755 半平面交+不等式
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 6461 | Accepted: 1643 |
Description
The speed of each contestant in all three sections is known. The judge can choose the length of each section arbitrarily provided that no section has zero length. As a result sometimes she could choose their lengths in such a way that some particular contestant would win the competition.
Input
Output
Sample Input
9
10 2 6
10 7 3
5 6 7
3 2 7
6 2 6
3 5 7
8 4 6
10 4 2
1 8 7
Sample Output
Yes
Yes
Yes
No
No
No
Yes
No
Yes
/*
poj 1755 半平面交+不等式 一个比赛分三个部分,每个人在三个部分的速度为U,V,W。每个赛道的长度不一定。
现在给你n个人的情况,问他们是否能得奖 总时间 t1 = x/u1+y/v1+z/w1 t2 = x/u2+y/v2+z/w2
那么 两个人的时间差 t = t1 - t2 = ax+by+cz,判断正负即可
所以 可以看成 (a/z)x+(b/z)y+c 就成了二元方程
然后利用半平面相交计算出这些不等式最后能否得到一个>0公共区域。
如果能,则说明冠军与你有缘诶 hhh-2016-05-17 22:32:51
*/
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
using namespace std;
const int maxn = 300;
const double PI = 3.1415926;
const double eps = 1e-16;
int n;
int sgn(double x)
{
if(fabs(x) < eps) return 0;
if(x < 0)
return -1;
else
return 1;
} struct Point
{
double x,y;
Point() {}
Point(double _x,double _y)
{
x = _x,y = _y;
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const
{
return x*b.y-y*b.x;
}
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
}; struct Line
{
Point s,t;
double k;
Line() {}
Line(Point _s,Point _t)
{
s = _s;
t = _t;
k = atan2(t.y-s.y,t.x-s.x);
}
Point operator &(const Line &b) const
{
Point res = s;
double ta = ((s-b.s)^(b.s-b.t))/((s-t)^(b.s-b.t));
res.x += (t.x-s.x)*ta;
res.y += (t.y-s.y)*ta;
return res;
}
}; //求p1,p2的直线与a,b,c这条直线的交点
Point Intersection(Point p1,Point p2,double a,double b,double c)
{
double u = fabs(a*p1.x + b*p1.y + c);
double v = fabs(a*p2.x + b*p2.y + c);
Point t;
t.x = (p1.x*v + p2.x*u)/(u+v);
t.y = (p1.y*v + p2.y*u)/(u+v);
return t;
} double CalArea(Point p[],int n)
{
double ans = 0;
for(int i = 0; i < n; i++)
{
ans += (p[i]^p[(i+1)%n])/2;
}
return fabs(ans);
} double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
} Point p[maxn];
Point tp[maxn];
void cut(double a,double b,double c,Point p[],int &cnt)
{
int tmp = 0;
for(int i = 1; i <= cnt; i++)
{
if(a*p[i].x+b*p[i].y+c < eps) tp[++tmp] = p[i];
else
{
//在p[i]处大于0,那么交点可能在(p[i-1],p[i])or(p[i+1],p[i])
if(a*p[i-1].x + b*p[i-1].y + c < -eps)
tp[++tmp] = Intersection(p[i-1],p[i],a,b,c);
if(a*p[i+1].x + b*p[i+1].y + c < -eps)
tp[++tmp] = Intersection(p[i],p[i+1],a,b,c);
}
}
for(int i = 1; i <= tmp; i++)
p[i] = tp[i];
p[0] = p[tmp];
p[tmp+1] = p[1];
cnt = tmp;
}
double inf = 1000000000000000.0;
double U[maxn],V[maxn],W[maxn];
bool cal(int now)
{
p[1] = Point(0,0);
p[2] = Point(0,inf);
p[3] = Point(inf,inf);
p[4] = Point(inf,0);
p[0] = p[4];
p[5] = p[1];
int cnt = 4;
for(int i = 0; i < n; i++)
{
if(i == now) continue;
double a = (U[i]-U[now])/(U[i]*U[now]); //1/U[now] - 1/U[i]
double b = (V[i]-V[now])/(V[i]*V[now]);
double c = (W[i]-W[now])/(W[i]*W[now]);
if(sgn(a)==0 && sgn(b) == 0 )
{
if(sgn(c) >= 0)
return false;
else
continue;
}
cut(a,b,c,p,cnt);
}
if(sgn(CalArea(p,cnt)) == 0)
return false;
else
return true;
} int main()
{
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!= EOF)
{
for(int i = 0; i < n; i++)
{
scanf("%lf%lf%lf",&U[i],&V[i],&W[i]);
}
for(int i = 0; i < n; i++)
{
if(cal(i))
printf("Yes\n");
else
printf("No\n");
}
}
return 0;
}
poj 1755 半平面交+不等式的更多相关文章
- poj 1279 半平面交核面积
Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6668 Accepted: 2725 Descr ...
- poj 3525 半平面交求多边形内切圆最大半径【半平面交】+【二分】
<题目链接> 题目大意:给出一个四面环海的凸多边形岛屿,求出这个岛屿中的点到海的最远距离. 解题分析: 仔细思考就会发现,其实题目其实就是让我们求该凸多边形内内切圆的最大半径是多少.但是, ...
- POJ 3525 /// 半平面交 模板
题目大意: 给定n,接下来n行逆时针给定小岛的n个顶点 输出岛内离海最远的点与海的距离 半平面交模板题 将整个小岛视为由许多半平面围成 那么以相同的比例缩小这些半平面 一直到缩小到一个点时 那个点就是 ...
- poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积
/*************** poj 3335 点序顺时针 ***************/ #include <iostream> #include <cmath> #i ...
- POJ 3525 半平面交+二分
二分所能形成圆的最大距离,然后将每一条边都向内推进这个距离,最后所有边组合在一起判断时候存在内部点 #include <cstdio> #include <cstring> # ...
- POJ 3335 Rotating Scoreboard 半平面交求核
LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...
- POJ 1755 Triathlon [半平面交 线性规划]
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6912 Accepted: 1790 Descrip ...
- POJ 1755 Triathlon(线性规划の半平面交)
Description Triathlon is an athletic contest consisting of three consecutive sections that should be ...
- POJ 1755 Triathlon (半平面交)
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4733 Accepted: 1166 Descrip ...
随机推荐
- EVA 4400存储硬盘故障数据恢复方案和数据恢复过程
EVA系列存储是一款以虚拟化存储为实现目的的HP中高端存储设备,平时数据会不断的迁移,加上任务通常较为繁重,所以磁盘的负载相对是较重的,也是很容易出现故障的.EVA是依靠大量磁盘的冗余空间,以及故障后 ...
- 使用静态基类方案让 ASP.NET Core 实现遵循 HATEOAS Restful Web API
Hypermedia As The Engine Of Application State (HATEOAS) HATEOAS(Hypermedia as the engine of applicat ...
- php代码开启缓冲的使用方法
php可以开启缓冲区,就是将内容放到缓冲区,再决定什么时候发送给浏览器. 感谢:http://www.jb51.net/article/38964.htm 解析PHP中ob_start()函数的用法 ...
- 第一章 创建WEB项目
第一章 创建WEB项目 一.Eclipse创建WEB项目 方法/步骤1 首先,你要先打开Eclipse软件,打开后在工具栏依次点击[File]>>>[New]>>&g ...
- 基于 Java NIO 实现简单的 HTTP 服务器
1.简介 本文是上一篇文章实践篇,在上一篇文章中,我分析了选择器 Selector 的原理.本篇文章,我们来说说 Selector 的应用,如标题所示,这里我基于 Java NIO 实现了一个简单的 ...
- Python内置函数(12)——str
英文文档: class str(object='') class str(object=b'', encoding='utf-8', errors='strict') Return a string ...
- Java Jar包压缩、解压使用指南
什么是jar包 JAR(Java Archive)是Java的归档文件,它是一种与平台无关的文件格式,它允许将许多文件组合成一个压缩文件. 如何打/解包 使用jdk/bin/jar.exe工具,配置完 ...
- linux搭建django项目基本步骤
一 linux下django基本项目搭建流程:M model 用于与数据库交互V view 接受前台请求 调用model获取结果,调用T获取页面,返回给前台T template 接受view的要求 生 ...
- java 中文乱码问题,请注意response.getWriter的顺序
反例: 正例:
- jsp 九大内置对象和其作用详解
JSP中一共预先定义了9个这样的对象,分别为:request.response.session.application.out.pagecontext.config.page.exception 1. ...