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 就好了

注意精度有毒。。。

代码

#include<bits/stdc++.h>
using namespace std; struct node
{
double x,y,z;
bool operator<(const node& p) const
{
if(z==p.z&&y==p.y)return x<p.x;
if(z==p.z)return y<p.y;
return z<p.z;
}
};
struct Tri
{
node p[3];
};
Tri tri[5006];
map<node,int> H;
map<int,node> T;
int tot = 1;
node A,B;
vector<int> E[7000];
int vis[7000];
int n;
void init()
{
memset(vis,0,sizeof(vis));
H.clear();
T.clear();
tot = 1;
for(int i=0;i<7000;i++)
E[i].clear();
memset(tri,0,sizeof(tri));
}
double eps = 1e-2;
double dis(node aa,node bb)
{
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));
}
double area(node aa,node bb,node cc)
{
double l1 = dis(aa,bb);
double l2 = dis(aa,cc);
double l3 = dis(bb,cc);
double pp = (l1+l2+l3)/2.0;
return sqrt(pp*(pp-l1)*(pp-l2)*(pp-l3));
}
int inRan(Tri kkk,node ttt)
{
double a1 = area(kkk.p[0],kkk.p[1],ttt);
double a2 = area(kkk.p[0],kkk.p[2],ttt);
double a3 = area(kkk.p[1],kkk.p[2],ttt);
double a4 = area(kkk.p[0],kkk.p[1],kkk.p[2]);
if(fabs(a4-a1-a2-a3)<=eps)return 1;
return 0;
}
void dfs(int x,int h)
{
vis[x]=1;
for(int i=0;i<E[x].size();i++)
{
int v = E[x][i];
if(vis[v])continue;
if(T[v].z>h)continue;
dfs(v,h);
}
}
int check(double h)
{
if(A.z>h||B.z>h)return 0;
memset(vis,0,sizeof(vis));
dfs(H[A],h);
if(vis[H[B]]==1)return 1;
return 0;
}
vector<node> TTT;
int flag = 0;
void dfs2(int x,double h)
{
if(flag)return;
TTT.push_back(T[x]);
if(x==H[B])
{
flag = 1;
cout<<TTT.size()<<endl;
for(int i=0;i<TTT.size();i++)
printf("%.0f %.0f %.0f\n",TTT[i].x,TTT[i].y,TTT[i].z);
return;
}
vis[x]=1;
for(int i=0;i<E[x].size();i++)
{
int v = E[x][i];
if(vis[v])continue;
if(T[v].z>h)continue;
dfs2(v,h);
TTT.pop_back();
}
}
int main()
{
freopen("hiking.in","r",stdin);
freopen("hiking.out","w",stdout);
init();
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=0;j<3;j++)
{
scanf("%lf%lf%lf",&tri[i].p[j].x,&tri[i].p[j].y,&tri[i].p[j].z);
if(H[tri[i].p[j]]==0)
{
T[tot] = tri[i].p[j];
H[tri[i].p[j]] = tot++;
}
}
for(int j=0;j<3;j++)
{
for(int k=j+1;k<3;k++)
{
E[H[tri[i].p[j]]].push_back(H[tri[i].p[k]]);
E[H[tri[i].p[k]]].push_back(H[tri[i].p[j]]);
}
}
}
scanf("%lf%lf%lf",&A.x,&A.y,&A.z);
scanf("%lf%lf%lf",&B.x,&B.y,&B.z);
if(H[A]==0)
{
T[tot] = A;
H[A] = tot++;
for(int i=1;i<=n;i++)
{
if(inRan(tri[i],A))
{
for(int j=0;j<3;j++)
{
E[H[A]].push_back(H[tri[i].p[j]]);
E[H[tri[i].p[j]]].push_back(H[A]);
}
}
}
}
if(H[B]==0)
{
T[tot] = B;
H[B] = tot++;
for(int i=1;i<=n;i++)
{
if(inRan(tri[i],B))
{
for(int j=0;j<3;j++)
{
E[H[B]].push_back(H[tri[i].p[j]]);
E[H[tri[i].p[j]]].push_back(H[B]);
}
}
}
}
double l = -2.0,r = 3000050.0;
for(int i=1;i<=100;i++)
{
double mid = (l+r)/2.0;
if(check(mid))r=mid;
else l=mid;
}
memset(vis,0,sizeof(vis));
TTT.clear();
dfs2(H[A],r+1);
}

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. JQuery实现分页程序代码,源码下载

    Web开发,分页在所难免的,微软GridView.AspPager等设置分页数据可以自动分页,但是这里浏览器会闪动,用户体验不是很友好,在此我整理了JQuery实现分页,并且使用 JQuery模板显示 ...

  2. C++ STL算法系列5---equal() , mismatch()

    equal和mismatch算法的功能是比较容器中的两个区间内的元素.这两个算法各有3个参数first1,last1和first2.如果对 于区间[first1,last1)内所有的first1+i, ...

  3. STL&quot;源码&quot;剖析-重点知识总结

    STL是C++重要的组件之一,大学时看过<STL源码剖析>这本书,这几天复习了一下,总结出以下LZ认为比较重要的知识点,内容有点略多 :) 1.STL概述 STL提供六大组件,彼此可以组合 ...

  4. Github在windows7环境下使用入门

    1.下载并安装 下载和安装一般都没什么问题,网上的链接一大堆,不过还是在此给一个安装的地址和安装的参考吧. 当然,安装完成后要保证git能使用,必须配置github 2.配置github 首先是要创建 ...

  5. c++声明与定义

    c++声明与定义 声明是将一个名称引入程序.定义提供了一个实体在程序中的唯一描述.声明和定义有时是同时存在的. 如 int  a; extern int b=1; 只有当extern中不存在初始化才是 ...

  6. 记拿到鹅厂前端开发暑期实习offer的经历

    #想起来时的路 在真正拿到腾讯实习offer之前,也是看过不少人的面经,心生向往.很早在入前端坑之前,我就想着大四的时候有机会要尝试去腾讯里实习. 大一入门语言就是C++,这让我很无奈,所以我很快的就 ...

  7. C++11能用智能指针

    [C++11能用智能指针] shared_ptr 是一引用计数 (reference-counted) 指针,其行为与一般 C++ 指针即为相似.在 TR1 的实现中,缺少了一些一般指针所拥有的特色, ...

  8. JSON如何序列图片

    图片采用JSON格式传输的话,需要把图片转成Base64格式. 首先把图片转成流:Image1.Picture.Graphic.SaveToStream(ss);然后编码成base64格式的:Enco ...

  9. [iOS微博项目 - 2.3] - 用户取消对app的授权

    github: https://github.com/hellovoidworld/HVWWeibo   A.用户取消对app的授权 用户可以在微博网站上取消对某个应用(app)的授权   1.打开& ...

  10. My集合框架第三弹 AVL树

    旋转操作: 由于任意一个结点最多只有两个儿子,所以当高度不平衡时,只可能是以下四种情况造成的: 1. 对该结点的左儿子的左子树进行了一次插入. 2. 对该结点的左儿子的右子树进行了一次插入. 3. 对 ...