uva 1298 - Triathlon
半平面交的题;
这个题目的亮点就是建模;
- #include<cstdio>
- #include<algorithm>
- #include<cmath>
- #define maxn 109
- #define eps 1e-6
- using namespace std;
- int dcmp(double x)
- {
- return fabs(x) < eps ? : (x > ? : -);
- }
- struct Point
- {
- double x;
- double y;
- Point(double x = , double y = ):x(x), y(y) {}
- };
- typedef Point Vector;
- Vector operator + (Point A, Point B)
- {
- return Vector(A.x + B.x, A.y + B.y);
- }
- Vector operator - (Point A, Point B)
- {
- return Vector(A.x - B.x, A.y - B.y);
- }
- Vector operator * (Point A, double p)
- {
- return Vector(A.x * p, A.y * p);
- }
- Vector operator / (Point A, double p)
- {
- return Vector(A.x / p, A.y / p);
- }
- double dot(Point a,Point b)
- {
- return a.x*b.x+a.y*b.y;
- }
- double cross(Point a,Point b)
- {
- return a.x*b.y-a.y*b.x;
- }
- Vector nomal(Vector a)
- {
- double l=sqrt(dot(a,a));
- return Vector(-a.y/l,a.x/l);
- }
- struct line
- {
- Point p;
- Vector v;
- double ang;
- line() {}
- line(Point p,Vector v):p(p),v(v)
- {
- ang=atan2(v.y,v.x);
- }
- bool operator<(const line &t)const
- {
- return ang<t.ang;
- }
- };
- bool onleft(line l,Point p)
- {
- return (cross(l.v,p-l.p)>);
- }
- Point getintersection(line a,line b)
- {
- Vector u=a.p-b.p;
- double t=cross(b.v,u)/cross(a.v,b.v);
- return a.p+a.v*t;
- }
- int halfplanintersection(line *l,int n,Point *poly)
- {
- sort(l,l+n);
- int first,last;
- Point *p=new Point[n];
- line *q=new line[n];
- q[first=last=]=l[];
- for(int i=; i<n; i++)
- {
- while(first<last && !onleft(l[i],p[last-]))last--;
- while(first<last && !onleft(l[i],p[first]))first++;
- q[++last]=l[i];
- if(fabs(cross(q[last].v,q[last-].v))<eps)
- {
- last--;
- if(onleft(q[last],l[i].p))q[last]=l[i];
- }
- if(first<last)p[last-]=getintersection(q[last-],q[last]);
- }
- while(first<last && !onleft(q[first],p[last-]))last--;
- if((last-first )<=)return ;
- p[last]=getintersection(q[last],q[first]);
- int m=;
- for(int i=first; i<=last; i++)poly[m++]=p[i];
- return m;
- }
- Point poly[maxn];
- line l[maxn];
- double v[maxn],u[maxn],w[maxn];
- int main()
- {
- int n;
- while(scanf("%d",&n)!=EOF)
- {
- for(int i=;i<n;i++)scanf("%lf%lf%lf",&v[i],&u[i],&w[i]);
- for(int i=;i<n;i++)
- {
- double k=;
- bool flag=;
- int cnt=;
- for(int j=;j<n;j++)
- {
- if(i==j)continue;
- if(v[j]>=v[i]&&u[j]>=u[i]&&w[j]>=w[i]){flag=;break;}
- if(v[j]<=v[i]&&w[j]<=u[i]&&w[j]<=w[i])continue;
- double a=(k/v[j]-k/w[j])-(k/v[i]-k/w[i]);
- double b=(k/u[j]-k/w[j])-(k/u[i]-k/w[i]);
- double c=k/w[j]-k/w[i];
- Point p;
- Vector v(b,-a);
- if(fabs(a)>fabs(b))p=Point(-c/a,);
- else p=Point(,-c/b);
- l[cnt++]=line(p,v);
- }
- if(flag)
- {
- l[cnt++]=line(Point(,),Vector(,-));
- l[cnt++]=line(Point(,),Vector(,));
- l[cnt++]=line(Point(,),Vector(-,));
- if(halfplanintersection(l,cnt,poly)==)flag=;
- }
- if(flag)puts("Yes");
- else puts("No");
- }
- }return ;
- }
uva 1298 - Triathlon的更多相关文章
- uva 2218 Triathlon
题意:铁人三项赛,给定每个选手游泳,自行车,赛跑三个阶段的平均速度,不知道每段比赛的路程,询问当前这个选手能否胜利. 思路:把题意转化为一个不等式,设比赛长度是1,如果i要战胜j,x.y分别是第一阶段 ...
- UVALive 4639 && SPOJ SPOINTS && POJ 3805 && AOJ 1298 Separate Points 求两个凸包是否相交 难度:3
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
随机推荐
- client 如何找到正确的RegionServer(HBase -ROOT-和.META.表)
在HBase中,大部分的操作都是在RegionServer完成的,Client端想要插入,删除,查询数据都需要先找到相应的RegionServer.什么叫相应的RegionServer?就是管理你要操 ...
- Microsoft SQL Server Product Samples:Database
从SQL Server 2005 之后示例数据都为AdventureWorks,需要的通过codeplex网站下载.这样设计的目的应该在于是生产库行不必要的用户以及权限分配. 从以下网址访问http: ...
- 禁止button响应回车(.net页面)
1. 深层次来说这不是 ASP.NET 的问题, 而是 html form 的 submit 按钮就是如何设计的. 当你的光标焦点进入某个表单元素的时候,会激活该表单中第一个(流布局顺从左到右,从上至 ...
- Oracle Text Slowly
When oracle text more and more slowly, execute the following script: ANALYZE TABLE Table_Name COMPU ...
- shell 数组
数组赋值:(1) array=(var1 var2 var3 ... varN)(2) array=([0]=var1 [1]=var2 [2]=var3 ... [n]=varN)(3) array ...
- ios 视频音乐播放
IOS开发小技巧(视频和音乐播放).IOS视频播放代码(添加MediaPlayer.framework和#import) -(void)playMovie:(NSString *)fileName{ ...
- json转换(c#后台生成json的方法)
此文转自:http://bbs.csdn.net/topics/380200497,为了方便自己记忆才以文章形式保存. using System; using System.Collections.G ...
- 带你初识Angular中MVC模型
简介 MVC是一种使用 MVC(Model View Controller 模型-视图-控制器)设计模式,该模型的理念也被许多框架所吸纳,比如,后端框架(Struts.Spring MVC等).前端框 ...
- DataGridView如何快速导出Excel
从DataGridView或DataTable导出Excel文件,为了按照数据类型设置单元格格式,导出Excel时速度都比较慢,一直找不到好的办法. 最后从外文网站上找到解决办法,使用ws.get_R ...
- Newtonsoft.Json.dll解析json的dll文件使用
要解析的json //解析前 //解析前 {,,,,,,,,,,},,,,,,,,,,,},,,,,,,,,,,,,,,,},,,,,,,,,},,,,,,,,,,,,},,,,,,,,,,,},,, ...