poj1755Triathlon(半平面交)
根据题意可以设三段路程分别为A,B,C
那么总时间t = A/V+B/U+C/W.
这样根据时间大小关系可以跟其余n-1个联立形成n-1个方程。
化简后为A(1/vj-1/vi)+B(1/uj-1/ui)+C(1/wj-1/wi)>0
这样就可以按照顺时针进行半平面交。初始需要加一个大的平面,可以加上4个点,(0,0) (0,INF) (INF,INF) (INF,0)
最后面积需》0
这个题精度要求高,在求系数的时候可以 (vi-vj)/(vi*vj) 来提高精度 ,只除一次。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 110
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
const int MAXN=;
int m,n;
double r;
int cCnt,curCnt;//此时cCnt为最终切割得到的多边形的顶点数、暂存顶点个数
struct point
{
double x,y;
point(double x=,double y=):x(x),y(y){}
};
struct node
{
int v,u,w;
}ll[N];
point points[MAXN],p[MAXN],q[MAXN];//读入的多边形的顶点(顺时针)、p为存放最终切割得到的多边形顶点的数组、暂存核的顶点
void getline(point x,point y,double &a,double &b,double &c) //两点x、y确定一条直线a、b、c为其系数
{
a = y.y - x.y;
b = x.x - y.x;
c = y.x * x.y - x.x * y.y;
}
void initial()
{
for(int i = ; i <= m; ++i)p[i] = points[i];
p[m+] = p[];
p[] = p[m];
cCnt = m;//cCnt为最终切割得到的多边形的顶点数,将其初始化为多边形的顶点的个数
}
point intersect(point x,point y,double a,double b,double c) //求x、y形成的直线与已知直线a、b、c、的交点
{
double u = fabs(a * x.x + b * x.y + c);
double v = fabs(a * y.x + b * y.y + c);
point pt;
pt.x=(x.x * v + y.x * u) / (u + v);
pt.y=(x.y * v + y.y * u) / (u + v);
return pt;
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
void cut(double a,double b ,double c)
{ curCnt = ;
for(int i = ; i <= cCnt; ++i)
{
if(a*p[i].x + b*p[i].y + c >-eps)q[++curCnt] = p[i];// c由于精度问题,可能会偏小,所以有些点本应在右侧而没在,
//故应该接着判断
else
{
if(a*p[i-].x + b*p[i-].y + c > eps) //如果p[i-1]在直线的右侧的话,
{
//则将p[i],p[i-1]形成的直线与已知直线的交点作为核的一个顶点(这样的话,由于精度的问题,核的面积可能会有所减少)
q[++curCnt] = intersect(p[i],p[i-],a,b,c);
}
if(a*p[i+].x + b*p[i+].y + c > eps) //原理同上
{
q[++curCnt] = intersect(p[i],p[i+],a,b,c);
}
}
}
for(int i = ; i <= curCnt; ++i)p[i] = q[i];//将q中暂存的核的顶点转移到p中
p[curCnt+] = q[];
p[] = p[curCnt];
cCnt = curCnt;
}
void solve(int k)
{
//注意:默认点是顺时针,如果题目不是顺时针,规整化方向
initial();
for(int i = ; i <= n; ++i)
{
if(i==k) continue;
double a,b,c;
a = (ll[k].u-ll[i].u)*1.0/(ll[k].u*ll[i].u);
b = (ll[k].w-ll[i].w)*1.0/(ll[k].w*ll[i].w);
c = (ll[k].v-ll[i].v)*1.0/(ll[k].v*ll[i].v);
if(dcmp(a)==&&dcmp(b)==&&dcmp(c)<=)
{
puts("No");
return ;
}
//getline(points[i],points[i+1],a,b,c);
cut(a,b,c);
}
/*
如果要向内推进r,用该部分代替上个函数
for(int i = 1; i <= m; ++i){
Point ta, tb, tt;
tt.x = points[i+1].y - points[i].y;
tt.y = points[i].x - points[i+1].x;
double k = r / sqrt(tt.x * tt.x + tt.y * tt.y);
tt.x = tt.x * k;
tt.y = tt.y * k;
ta.x = points[i].x + tt.x;
ta.y = points[i].y + tt.y;
tb.x = points[i+1].x + tt.x;
tb.y = points[i+1].y + tt.y;
double a,b,c;
getline(ta,tb,a,b,c);
cut(a,b,c);
}*/
//多边形核的面积
double area = ;
for(int i = ; i <= cCnt; ++i)
area += p[i].x * p[i + ].y - p[i + ].x * p[i].y;
area = fabs(area / 2.0);
if(dcmp(area)>)
printf("Yes\n");
else
puts("No"); }
/*void GuiZhengHua(){
//规整化方向,逆时针变顺时针,顺时针变逆时针
for(int i = 1; i < (m+1)/2; i ++)
swap(points[i], points[m-i]);
}*/
int main()
{
points[] = point(,);
points[] = point(INF,);
points[] = point(INF,INF);
points[] = point(,INF);
points[] = points[];
m = ;
int i;
while(scanf("%d",&n)!=EOF)
{
for(i = ; i <=n ;i++)
scanf("%d%d%d",&ll[i].v,&ll[i].u,&ll[i].w);
for(i = ;i <= n ;i++)
solve(i);
}
return ;
}
poj1755Triathlon(半平面交)的更多相关文章
- 【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)
按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径. 二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了. 平移直线就是对于向量ab,因为是逆时针的,向中 ...
- 【BZOJ-2618】凸多边形 计算几何 + 半平面交 + 增量法 + 三角剖分
2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 959 Solved: 489[Submit][Status] ...
- 【CSU1812】三角形和矩形 【半平面交】
检验半平面交的板子. #include <stdio.h> #include <bits/stdc++.h> using namespace std; #define gg p ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
- poj 3335(半平面交)
链接:http://poj.org/problem?id=3335 //大牛们常说的测模板题 ------------------------------------------------- ...
- poj3525Most Distant Point from the Sea(半平面交)
链接 求凸多边形内一点距离边最远. 做法:二分+半平面交判定. 二分距离,每次让每条边向内推进d,用半平面交判定一下是否有核. 本想自己写一个向内推进..仔细一看发现自己的平面交模板上自带.. #in ...
- poj1474Video Surveillance(半平面交)
链接 半平面交的模板题,判断有没有核.: 注意一下最后的核可能为一条线,面积也是为0的,但却是有的. #include<iostream> #include <stdio.h> ...
- 半平面交模板(O(n*n)&& O(n*log(n))
摘自http://blog.csdn.net/accry/article/details/6070621 首先解决问题:什么是半平面? 顾名思义,半平面就是指平面的一半,我们知道,一条直线可以将平面分 ...
- POJ2451 Uyuw's Concert(半平面交)
题意就是给你很多个半平面,求半平面交出来的凸包的面积. 半平面交有O(n^2)的算法,就是每次用一个新的半平面去切已有的凸包,更新,这个写起来感觉也不是特别好写. 另外一个O(nlogn)的算法是将半 ...
- POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)
题目链接 题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少. 思路 :先二分半径r,半平面交向内推进r.模板题 #include <stdio.h> #include & ...
随机推荐
- HDU 5818:Joint Stacks(stack + deque)
http://acm.hdu.edu.cn/showproblem.php?pid=5818 Joint Stacks Problem Description A stack is a data ...
- 不定参数的传递VA_LIST的用法
VA_LIST的用法:(1)首先在函数里定义一具VA_LIST型的变量,这个变量是指向参数的指针: (2)然后用VA_START宏初始化变量刚定义的VA_LIST变量,使其指向第一个可 变参数的地址: ...
- [ios][swift]swift GPS传感器的调用
在Info.plist文件中添加如下配置:(1)NSLocationAlwaysUsageDescription(2)NSLocationWhenInUseUsageDescription swift ...
- jqeury轮播
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- 怎样解决:未找到路径“……”的控制器或该控制器未实现 IController?
就是要加上new{area=""},比如下面的: @{Html.RenderAction("Cartsummary","ShoppingCart&qu ...
- 使用MSCOMM发送任意文件,还有一些注意事项
第一步:发送文件 FILE* pSENDFILE = _wfopen(m_edit_chosefile, _T("rb"));//以二进制打开待发送文件的的文件指针 fseek(p ...
- 如何解决Angular 2 的templateUrl和styleUrl的路径问题?
参考地址:https://github.com/kittencup/angular2-ama-cn/issues/18 前言: templateUrl表示的是组件在浏览器中运行时依赖的模板地址,所以在 ...
- 面向对象--类库、委托、is和as运算符、泛型集合
类库: 其实就是一堆类文件,只是看不到这些类的源代码,保密性好. 优点:保密性好 缺点:如果这个方法不好用,使用者无法自己去更改它. 给的大多是dll文件.使用方法:引用右键,添加引用,浏览,选择到相 ...
- JS如何将CST格式的日期转换为制定格式String
<html> <body> <script type="text/javascript"> var d = new Date() dateFor ...
- jsp利用cookie记住用户名,下次登录时显示在文本框中(仅仅一个Cookie就整了将近三个小时,⊙﹏⊙b汗)
<%@page import="java.net.URLDecoder"%> <%@page import="sun.security.util.Len ...