半平面交的题;

这个题目的亮点就是建模;

  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<cmath>
  4. #define maxn 109
  5. #define eps 1e-6
  6. using namespace std;
  7.  
  8. int dcmp(double x)
  9. {
  10. return fabs(x) < eps ? : (x > ? : -);
  11. }
  12.  
  13. struct Point
  14. {
  15. double x;
  16. double y;
  17. Point(double x = , double y = ):x(x), y(y) {}
  18. };
  19. typedef Point Vector;
  20.  
  21. Vector operator + (Point A, Point B)
  22. {
  23. return Vector(A.x + B.x, A.y + B.y);
  24. }
  25.  
  26. Vector operator - (Point A, Point B)
  27. {
  28. return Vector(A.x - B.x, A.y - B.y);
  29. }
  30.  
  31. Vector operator * (Point A, double p)
  32. {
  33. return Vector(A.x * p, A.y * p);
  34. }
  35.  
  36. Vector operator / (Point A, double p)
  37. {
  38. return Vector(A.x / p, A.y / p);
  39. }
  40. double dot(Point a,Point b)
  41. {
  42. return a.x*b.x+a.y*b.y;
  43. }
  44. double cross(Point a,Point b)
  45. {
  46. return a.x*b.y-a.y*b.x;
  47. }
  48.  
  49. Vector nomal(Vector a)
  50. {
  51. double l=sqrt(dot(a,a));
  52. return Vector(-a.y/l,a.x/l);
  53. }
  54.  
  55. struct line
  56. {
  57. Point p;
  58. Vector v;
  59. double ang;
  60. line() {}
  61. line(Point p,Vector v):p(p),v(v)
  62. {
  63. ang=atan2(v.y,v.x);
  64. }
  65. bool operator<(const line &t)const
  66. {
  67. return ang<t.ang;
  68. }
  69. };
  70.  
  71. bool onleft(line l,Point p)
  72. {
  73. return (cross(l.v,p-l.p)>);
  74. }
  75.  
  76. Point getintersection(line a,line b)
  77. {
  78. Vector u=a.p-b.p;
  79. double t=cross(b.v,u)/cross(a.v,b.v);
  80. return a.p+a.v*t;
  81. }
  82.  
  83. int halfplanintersection(line *l,int n,Point *poly)
  84. {
  85. sort(l,l+n);
  86. int first,last;
  87. Point *p=new Point[n];
  88. line *q=new line[n];
  89. q[first=last=]=l[];
  90. for(int i=; i<n; i++)
  91. {
  92. while(first<last && !onleft(l[i],p[last-]))last--;
  93. while(first<last && !onleft(l[i],p[first]))first++;
  94. q[++last]=l[i];
  95. if(fabs(cross(q[last].v,q[last-].v))<eps)
  96. {
  97. last--;
  98. if(onleft(q[last],l[i].p))q[last]=l[i];
  99. }
  100. if(first<last)p[last-]=getintersection(q[last-],q[last]);
  101. }
  102. while(first<last && !onleft(q[first],p[last-]))last--;
  103. if((last-first )<=)return ;
  104. p[last]=getintersection(q[last],q[first]);
  105. int m=;
  106. for(int i=first; i<=last; i++)poly[m++]=p[i];
  107. return m;
  108. }
  109.  
  110. Point poly[maxn];
  111. line l[maxn];
  112. double v[maxn],u[maxn],w[maxn];
  113.  
  114. int main()
  115. {
  116. int n;
  117. while(scanf("%d",&n)!=EOF)
  118. {
  119. for(int i=;i<n;i++)scanf("%lf%lf%lf",&v[i],&u[i],&w[i]);
  120. for(int i=;i<n;i++)
  121. {
  122. double k=;
  123. bool flag=;
  124. int cnt=;
  125. for(int j=;j<n;j++)
  126. {
  127. if(i==j)continue;
  128. if(v[j]>=v[i]&&u[j]>=u[i]&&w[j]>=w[i]){flag=;break;}
  129. if(v[j]<=v[i]&&w[j]<=u[i]&&w[j]<=w[i])continue;
  130. double a=(k/v[j]-k/w[j])-(k/v[i]-k/w[i]);
  131. double b=(k/u[j]-k/w[j])-(k/u[i]-k/w[i]);
  132. double c=k/w[j]-k/w[i];
  133. Point p;
  134. Vector v(b,-a);
  135. if(fabs(a)>fabs(b))p=Point(-c/a,);
  136. else p=Point(,-c/b);
  137. l[cnt++]=line(p,v);
  138. }
  139. if(flag)
  140. {
  141. l[cnt++]=line(Point(,),Vector(,-));
  142. l[cnt++]=line(Point(,),Vector(,));
  143. l[cnt++]=line(Point(,),Vector(-,));
  144. if(halfplanintersection(l,cnt,poly)==)flag=;
  145. }
  146. if(flag)puts("Yes");
  147. else puts("No");
  148. }
  149.  
  150. }return ;
  151. }

uva 1298 - Triathlon的更多相关文章

  1. uva 2218 Triathlon

    题意:铁人三项赛,给定每个选手游泳,自行车,赛跑三个阶段的平均速度,不知道每段比赛的路程,询问当前这个选手能否胜利. 思路:把题意转化为一个不等式,设比赛长度是1,如果i要战胜j,x.y分别是第一阶段 ...

  2. 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 ...

  3. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  4. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  5. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  6. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  7. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

  8. 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 ...

  9. UVA - 1625 Color Length[序列DP 代价计算技巧]

    UVA - 1625 Color Length   白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束   和模拟赛那道环形DP很想,计算这 ...

随机推荐

  1. client 如何找到正确的RegionServer(HBase -ROOT-和.META.表)

    在HBase中,大部分的操作都是在RegionServer完成的,Client端想要插入,删除,查询数据都需要先找到相应的RegionServer.什么叫相应的RegionServer?就是管理你要操 ...

  2. Microsoft SQL Server Product Samples:Database

    从SQL Server 2005 之后示例数据都为AdventureWorks,需要的通过codeplex网站下载.这样设计的目的应该在于是生产库行不必要的用户以及权限分配. 从以下网址访问http: ...

  3. 禁止button响应回车(.net页面)

    1. 深层次来说这不是 ASP.NET 的问题, 而是 html form 的 submit 按钮就是如何设计的. 当你的光标焦点进入某个表单元素的时候,会激活该表单中第一个(流布局顺从左到右,从上至 ...

  4. Oracle Text Slowly

    When  oracle text more and more slowly, execute the following script: ANALYZE TABLE Table_Name COMPU ...

  5. shell 数组

    数组赋值:(1) array=(var1 var2 var3 ... varN)(2) array=([0]=var1 [1]=var2 [2]=var3 ... [n]=varN)(3) array ...

  6. ios 视频音乐播放

    IOS开发小技巧(视频和音乐播放).IOS视频播放代码(添加MediaPlayer.framework和#import) -(void)playMovie:(NSString *)fileName{ ...

  7. json转换(c#后台生成json的方法)

    此文转自:http://bbs.csdn.net/topics/380200497,为了方便自己记忆才以文章形式保存. using System; using System.Collections.G ...

  8. 带你初识Angular中MVC模型

    简介 MVC是一种使用 MVC(Model View Controller 模型-视图-控制器)设计模式,该模型的理念也被许多框架所吸纳,比如,后端框架(Struts.Spring MVC等).前端框 ...

  9. DataGridView如何快速导出Excel

    从DataGridView或DataTable导出Excel文件,为了按照数据类型设置单元格格式,导出Excel时速度都比较慢,一直找不到好的办法. 最后从外文网站上找到解决办法,使用ws.get_R ...

  10. Newtonsoft.Json.dll解析json的dll文件使用

    要解析的json //解析前 //解析前 {,,,,,,,,,,},,,,,,,,,,,},,,,,,,,,,,,,,,,},,,,,,,,,},,,,,,,,,,,,},,,,,,,,,,,},,, ...