Problem H. Hiking in the Hills

题目连接:

http://codeforces.com/gym/100531/attachments

Description

Helen is hiking with her friends in a highland. Their plan is to hike from their camp A to a beautiful

showplace B.

Unfortunately, Helen started feeling dizzy due to altitude sickness. Help her group find a route such that

the topmost height on that route is as small as possible.

Input

The input file contains full information about the landscape of a square region 106 × 106

in the following

format. The first line contains integer n — the number of triangles in the landscape (2 ≤ n ≤ 2000).

Each of following n lines contains nine integers xi1, yi1, zi1, xi2, yi2, zi2, xi3, yi3, zi3 — coordinates of a

triangle. All coordinates belong to the closed interval [0, 106

]. The two last lines contain three integers

each: xA, yA, zA and xB, yB, zB — coordinates of the camp A and the showplace B.

The given triangles are guaranteed to describe a consistent continuous landscape. Projections of triangles

onto XY plane are non-degenerate and fill the square without overlapping. A vertex of one triangle never

lays inside an edge of another triangle. Points A and B belong to the landscape surface and are different.

Output

Output a polyline route from A to B with the smallest possible topmost height. The first line should

contain m, the number of vertices in this polyline. Each of following m lines should contain three integer

coordinates of a polyline vertex: xi

, yi

, and zi

. Vertices must be listed along the polyline, from A to B

(including these two endpoints).

All coordinates of polyline vertices should be integer. Each polyline edge must belong to some triangle

from the input file (possibly, to its edge). The number of vertices in the polyline must not exceed 5n.

Sample Input

8

1000000 0 0 1000000 1000000 150000 600000 600000 400000

0 1000000 0 600000 600000 400000 600000 1000000 300000

0 1000000 0 400000 300000 150000 600000 600000 400000

400000 0 200000 1000000 0 0 400000 300000 150000

400000 300000 150000 1000000 0 0 600000 600000 400000

600000 600000 400000 1000000 1000000 150000 600000 1000000 300000

0 0 0 400000 0 200000 400000 300000 150000

0 1000000 0 0 0 0 400000 300000 150000

100000 700000 37500

900000 400000 137500

Sample Output

4

100000 700000 37500

400000 300000 150000

900000 150000 100000

900000 400000 137500

Hint

题意

给你一个多面体,每个平面都是一个三角形

然后给你一个A点和B点,你需要输出一个从A到B的路径,使得这条路径的最高点最低

题解:

首先,走点一定是可行的,所以我们就可以不用去考虑边。

在一个三角形内的话,就连一条边。

然后我们直接二分高度,然后每次CHECK A是否能到B 就好了

注意精度有毒。。。

代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct node
  4. {
  5. double x,y,z;
  6. bool operator<(const node& p) const
  7. {
  8. if(z==p.z&&y==p.y)return x<p.x;
  9. if(z==p.z)return y<p.y;
  10. return z<p.z;
  11. }
  12. };
  13. struct Tri
  14. {
  15. node p[3];
  16. };
  17. Tri tri[5006];
  18. map<node,int> H;
  19. map<int,node> T;
  20. int tot = 1;
  21. node A,B;
  22. vector<int> E[7000];
  23. int vis[7000];
  24. int n;
  25. void init()
  26. {
  27. memset(vis,0,sizeof(vis));
  28. H.clear();
  29. T.clear();
  30. tot = 1;
  31. for(int i=0;i<7000;i++)
  32. E[i].clear();
  33. memset(tri,0,sizeof(tri));
  34. }
  35. double eps = 1e-2;
  36. double dis(node aa,node bb)
  37. {
  38. return sqrt((aa.x-bb.x)*(aa.x-bb.x)+(aa.y-bb.y)*(aa.y-bb.y)+(aa.z-bb.z)*(aa.z-bb.z));
  39. }
  40. double area(node aa,node bb,node cc)
  41. {
  42. double l1 = dis(aa,bb);
  43. double l2 = dis(aa,cc);
  44. double l3 = dis(bb,cc);
  45. double pp = (l1+l2+l3)/2.0;
  46. return sqrt(pp*(pp-l1)*(pp-l2)*(pp-l3));
  47. }
  48. int inRan(Tri kkk,node ttt)
  49. {
  50. double a1 = area(kkk.p[0],kkk.p[1],ttt);
  51. double a2 = area(kkk.p[0],kkk.p[2],ttt);
  52. double a3 = area(kkk.p[1],kkk.p[2],ttt);
  53. double a4 = area(kkk.p[0],kkk.p[1],kkk.p[2]);
  54. if(fabs(a4-a1-a2-a3)<=eps)return 1;
  55. return 0;
  56. }
  57. void dfs(int x,int h)
  58. {
  59. vis[x]=1;
  60. for(int i=0;i<E[x].size();i++)
  61. {
  62. int v = E[x][i];
  63. if(vis[v])continue;
  64. if(T[v].z>h)continue;
  65. dfs(v,h);
  66. }
  67. }
  68. int check(double h)
  69. {
  70. if(A.z>h||B.z>h)return 0;
  71. memset(vis,0,sizeof(vis));
  72. dfs(H[A],h);
  73. if(vis[H[B]]==1)return 1;
  74. return 0;
  75. }
  76. vector<node> TTT;
  77. int flag = 0;
  78. void dfs2(int x,double h)
  79. {
  80. if(flag)return;
  81. TTT.push_back(T[x]);
  82. if(x==H[B])
  83. {
  84. flag = 1;
  85. cout<<TTT.size()<<endl;
  86. for(int i=0;i<TTT.size();i++)
  87. printf("%.0f %.0f %.0f\n",TTT[i].x,TTT[i].y,TTT[i].z);
  88. return;
  89. }
  90. vis[x]=1;
  91. for(int i=0;i<E[x].size();i++)
  92. {
  93. int v = E[x][i];
  94. if(vis[v])continue;
  95. if(T[v].z>h)continue;
  96. dfs2(v,h);
  97. TTT.pop_back();
  98. }
  99. }
  100. int main()
  101. {
  102. freopen("hiking.in","r",stdin);
  103. freopen("hiking.out","w",stdout);
  104. init();
  105. scanf("%d",&n);
  106. for(int i=1;i<=n;i++)
  107. {
  108. for(int j=0;j<3;j++)
  109. {
  110. scanf("%lf%lf%lf",&tri[i].p[j].x,&tri[i].p[j].y,&tri[i].p[j].z);
  111. if(H[tri[i].p[j]]==0)
  112. {
  113. T[tot] = tri[i].p[j];
  114. H[tri[i].p[j]] = tot++;
  115. }
  116. }
  117. for(int j=0;j<3;j++)
  118. {
  119. for(int k=j+1;k<3;k++)
  120. {
  121. E[H[tri[i].p[j]]].push_back(H[tri[i].p[k]]);
  122. E[H[tri[i].p[k]]].push_back(H[tri[i].p[j]]);
  123. }
  124. }
  125. }
  126. scanf("%lf%lf%lf",&A.x,&A.y,&A.z);
  127. scanf("%lf%lf%lf",&B.x,&B.y,&B.z);
  128. if(H[A]==0)
  129. {
  130. T[tot] = A;
  131. H[A] = tot++;
  132. for(int i=1;i<=n;i++)
  133. {
  134. if(inRan(tri[i],A))
  135. {
  136. for(int j=0;j<3;j++)
  137. {
  138. E[H[A]].push_back(H[tri[i].p[j]]);
  139. E[H[tri[i].p[j]]].push_back(H[A]);
  140. }
  141. }
  142. }
  143. }
  144. if(H[B]==0)
  145. {
  146. T[tot] = B;
  147. H[B] = tot++;
  148. for(int i=1;i<=n;i++)
  149. {
  150. if(inRan(tri[i],B))
  151. {
  152. for(int j=0;j<3;j++)
  153. {
  154. E[H[B]].push_back(H[tri[i].p[j]]);
  155. E[H[tri[i].p[j]]].push_back(H[B]);
  156. }
  157. }
  158. }
  159. }
  160. double l = -2.0,r = 3000050.0;
  161. for(int i=1;i<=100;i++)
  162. {
  163. double mid = (l+r)/2.0;
  164. if(check(mid))r=mid;
  165. else l=mid;
  166. }
  167. memset(vis,0,sizeof(vis));
  168. TTT.clear();
  169. dfs2(H[A],r+1);
  170. }

Gym 100531H Problem H. Hiking in the Hills 二分的更多相关文章

  1. Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

    Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...

  2. Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

    Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  3. codeforce gym/100495/problem/K—Wolf and sheep 两圆求相交面积 与 gym/100495/problem/E—Simple sequence思路简述

    之前几乎没写过什么这种几何的计算题.在众多大佬的博客下终于记起来了当时的公式.嘚赶快补计算几何和概率论的坑了... 这题的要求,在对两圆相交的板子略做修改后,很容易实现.这里直接给出代码.重点的部分有 ...

  4. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem H. Password Service dp

    Problem H. Password Service 题目连接: http://www.codeforces.com/gym/100253 Description Startups are here ...

  5. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem H. Hometask 水题

    Problem H. Hometask 题目连接: http://codeforces.com/gym/100714 Description Kolya is still trying to pass ...

  6. 实验12:Problem H: 整型数组运算符重载

    Home Web Board ProblemSet Standing Status Statistics   Problem H: 整型数组运算符重载 Problem H: 整型数组运算符重载 Tim ...

  7. The Ninth Hunan Collegiate Programming Contest (2013) Problem H

    Problem H High bridge, low bridge Q: There are one high bridge and one low bridge across the river. ...

  8. 清北学堂入学测试P4751 H’s problem(h)

    P4751 H’s problem(h)  时间: 1000ms / 空间: 655360KiB / Java类名: Main 背景 冬令营入学测试 描述 小H是一个喜欢逛街的女孩子,但是由于上了大学 ...

  9. Problem H

    Problem Description 穿过幽谷意味着离大魔王lemon已经无限接近了! 可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫的考验,这是魔王lemon设下的又一个 ...

随机推荐

  1. Storage Keepers

    题意: n个仓库,m个人申请看管仓库,一个人可以看管多个仓库,一个仓库只能被一个人看管,每个人都有一个能力值,他看管的仓库的安全度U是能力值/看管仓库数,安全线L是U中的最小值,有多少能力公司发多少工 ...

  2. 【LeetCode 238】Product of Array Except Self

    Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...

  3. linux_2015_0827_linux中一些常用词的发音and…

    linux相关 Unix: [ ju:niks ] 发音 (yew-nicks) 尤里克斯 GNU [ gəˈnju: ] 发音 (guh-noo) 葛扭 Linux: [ 'li:nэks ] 里那 ...

  4. JAVA分析html算法(JAVA网页蜘蛛算法)

    近来有些朋友在做蜘蛛算法,或者在网页上面做深度的数据挖掘.但是遇到复杂而繁琐的html页面大家都望而却步.因为很难获取到相应的数据. 最古老的办法的是尝试用正则表达式,估计那么繁琐的东西得不偿失,浪费 ...

  5. wifi reaver

    PIN码的格式很简单, 八位十进制数,最后一位(第8位)为校验位(可根据前7位算出),验证时先检测前4位,如果一致则反馈一个信息,所以只需1万次就可完全扫描一遍前4位,前4位确定下来的话,只需再试10 ...

  6. reds pub/sub官方文档翻译

    Publish / Subscribe发布/订阅 redis-py includes a PubSub object that subscribes to channels and listens f ...

  7. 原生JS默认设置默认值的写法

    json=json||{};json.type=json.type||'get';json.data=json.data||{};json.time=json.time||2000;

  8. 【EasyUI】Combobox的联动和onChange/onSelect事件绑定

    [效果图] (1)当选择“产品名称”这个查询项目时,运算条件只有“等于”和“不等于”,如下图所示. (2)当用户选择可以进行数值计算的查询项目时,运算条件就会有很多,如下图所示. [实现代码] 1.H ...

  9. Linux查找文件夹名

    @(编程) find / -type d -name filename type的类型 -type c File is of type c: b block (buffered) special c ...

  10. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...