精度有点毒, 其实可以不用double, 因为A, B必定在其中一个在三角形上,可以投影到只有x,y轴的地方叉积比较。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define PLI pair<LL, int>
#define PLL pair<LL, LL>
#define ull unsigned long long
using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int dcmp(double x) {
if(fabs(x) <= eps) return ;
return x < ? - : ;
} struct Point3 {
double x, y, z;
Point3(double x=, double y=, double z=):x(x), y(y), z(z) {}
bool operator < (const Point3 &rhs) const {
if(x == rhs.x && y == rhs.y) return z < rhs.z;
else if(x == rhs.x) return y < rhs.y;
else return x < rhs.x;
}
bool operator == (const Point3 &rhs) const {
return dcmp(x-rhs.x)== && dcmp(y-rhs.y) == && dcmp(z-rhs.z == );
}
}; typedef Point3 Vector3; Vector3 operator + (Vector3 A, Vector3 B) {
return Vector3(A.x+B.x, A.y+B.y, A.z+B.z);
}
Vector3 operator - (Vector3 A, Vector3 B) {
return Vector3(A.x-B.x, A.y-B.y, A.z-B.z);
}
Vector3 operator * (Vector3 A, double p) {
return Vector3(A.x*p, A.y*p, A.z*p);
}
Vector3 operator / (Vector3 A, double p) {
return Vector3(A.x/p, A.y/p, A.z/p);
}
double Dot(Vector3 A, Vector3 B) {
return A.x*B.x + A.y*B.y + A.z*B.z;
}
double Length(Vector3 A) {
return sqrt(Dot(A, A));
}
double Angle(Vector3 A, Vector3 B) {
return acos(Dot(A, B)/Length(A)/Length(B));
}
Vector3 Cross(Vector3 A, Vector3 B) {
return Vector3(A.y*B.z-A.z*B.y, A.z*B.x-A.x*B.z, A.x*B.y-A.y*B.x);
}
double Area2(Point3 A, Point3 B, Point3 C) {
return Length(Cross(B-A, C-A));
}
bool PointInTri(Point3 P, Point3 P0, Point3 P1, Point3 P2) {
double area1 = Area2(P, P0, P1);
double area2 = Area2(P, P1, P2);
double area3 = Area2(P, P2, P0);
return dcmp(area1+area2+area3-Area2(P0, P1, P2)) == ;
} int n, tot, who1, who2;
Point3 tri[N][], a[N*], A, B;
vector<int> edge[N*];
vector<int> path, tmp, ans;
bool vis[N*]; inline int getId(Point3 &p) {
return lower_bound(a+, a++tot, p)-a;
} void dfs(int u, bool &flag, double up) {
if(flag) return;
vis[u] = true;
path.push_back(u);
if(u == who2) {
tmp = path;
flag = true;
}
for(int v : edge[u]) {
if(vis[v] || a[v].z > up) continue;
dfs(v, flag, up);
}
path.pop_back();
} bool check(double up) {
bool flag = false;
memset(vis, , sizeof(vis));
dfs(who1, flag, up);
return flag;
} int main() {
freopen("hiking.in", "r", stdin);
freopen("hiking.out", "w", stdout);
scanf("%d", &n);
for(int i = ; i <= n; i++) {
for(int j = ; j < ; j++) {
scanf("%lf%lf%lf", &tri[i][j].x, &tri[i][j].y, &tri[i][j].z);
a[++tot] = tri[i][j];
}
}
scanf("%lf%lf%lf", &A.x, &A.y, &A.z);
scanf("%lf%lf%lf", &B.x, &B.y, &B.z);
a[++tot] = A; a[++tot] = B;
sort(a+, a++tot);
tot = unique(a+, a++tot)-a-;
who1 = getId(A); who2 = getId(B);
for(int i = ; i <= n; i++) {
int id0 = getId(tri[i][]);
int id1 = getId(tri[i][]);
int id2 = getId(tri[i][]);
edge[id0].push_back(id1);
edge[id1].push_back(id0);
edge[id0].push_back(id2);
edge[id2].push_back(id0);
edge[id1].push_back(id2);
edge[id2].push_back(id1);
if(PointInTri(A, tri[i][], tri[i][], tri[i][])) {
edge[who1].push_back(id0);
edge[who1].push_back(id1);
edge[who1].push_back(id2);
edge[id0].push_back(who1);
edge[id1].push_back(who1);
edge[id2].push_back(who1);
}
if(PointInTri(B, tri[i][], tri[i][], tri[i][])) {
edge[who2].push_back(id0);
edge[who2].push_back(id1);
edge[who2].push_back(id2);
edge[id0].push_back(who2);
edge[id1].push_back(who2);
edge[id2].push_back(who2);
}
}
double low = max(A.z, B.z), high = 1e6;
for(int i = ; i <= ; i++) {
double mid = (low+high)/;
if(check(mid)) high = mid, ans = tmp;
else low = mid;
}
printf("%d\n", ans.size());
for(int &t : ans) {
printf("%d %d %d\n", (int)(a[t].x+0.5), (int)(a[t].y+0.5), (int)(a[t].z+0.5));
}
return ;
} /*
*/

gym 100531 三维几何+搜索的更多相关文章

  1. hdu 1240:Asteroids!(三维BFS搜索)

    Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  2. hdu 5839(三维几何)

    Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  3. Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度

    原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...

  4. Codeforces Gym 100231F Solitaire 折半搜索

    Solitaire 题目连接: http://codeforces.com/gym/100231/ Description 给你一个8*8棋盘,里面有4个棋子,每个棋子可以做一下某个操作之一: 1.走 ...

  5. GYM 100608G 记忆化搜索+概率 2014-2015 Winter Petrozavodsk Camp, Andrew Stankevich Contest 47 (ASC 47)

    https://codeforces.com/gym/100608 题意: 两个人玩游戏,每个人有一个长为d的b进制数字,两个人轮流摇一个$[0,b-1]$的骰子,并将选出的数字填入自己的d个空位之中 ...

  6. POJ 2177 Ghost Busters(三维几何)

    Description The famous Ghost Busters team has decided to upgrade their Ectomobile (aka Ecto-1) with ...

  7. HDU 4617 Weapon(三维几何)

    Problem Description Doctor D. are researching for a horrific weapon. The muzzle of the weapon is a c ...

  8. hdu 4617 Weapon【异面直线距离——基础三维几何】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4617 Weapon Time Limit: 3000/1000 MS (Java/Others)     ...

  9. kuangbin专题总结一 简单搜索

    A - 棋盘问题:在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有 ...

随机推荐

  1. [USACO09NOV]硬币的游戏A Coin Game

    https://daniu.luogu.org/problemnew/show/P2964 dp[i][j] 表示桌面上还剩i枚硬币时,上一次取走了j个的最大得分 枚举这一次要拿k个,转移到dp[i- ...

  2. charles抓包详解http 与 https

    包工具多种多样,比较好使的还是Charles和Fiddler,下面就简单的介绍下HTTPS的相关原理并以Charles为例来介绍下如何抓取HTTPS协议的包 1.下载charles 可以去charle ...

  3. EM算法(Expectation Maximization Algorithm)

    EM算法(Expectation Maximization Algorithm) 1. 前言   这是本人写的第一篇博客(2013年4月5日发在cnblogs上,现在迁移过来),是学习李航老师的< ...

  4. python json dumps loads

    请看以上图片可知 1. python requests里面返回的是json 字符串, 说白了是字符串.不能直接取里面对应的值. 2. 取值的话,需要把json字符串转换成字典, 用json.loads ...

  5. 退役 AFO

    noi滚粗了 D类没学校要 回去高考 此博客停止更新 此文章可能会继续更新 看心情 [upd 2017.11.13] 看完今年noip log级别数据结构终于出现辣! 看来noip以后又多了一大块考点 ...

  6. java反射三种获得类类型的方法

    public class Test { public static void main(String[] args) { Test t=new Test();//所有的类都是Class类的实例(类类型 ...

  7. 使用win10 hyper-v安装linux系统

    1.控制面板---程序---启动或关闭windows功能---启动hyper-v管理器---重启 2.配置网络 因为公司内网通过ip验证,而通过桥接的方式,虚拟机就相当于物理机所在的网络中的一台真实主 ...

  8. GreenTrend

    ExpertforSQLServer(4.7.2)和ZhuanCloud(1.0.0)工具收集内容(在个人笔记本上测试) --SZC_Info.txt :: SQL专家云 v1. :: 开始收集 :: ...

  9. Mysql注入root权限直接写一句话马

    首先我们的找到一个有注入的站:这里我用自己搭建的环境表示:大家不要乱来 http://localhost/pentest/sql/sql_injection_get.php?id=1 发现是root权 ...

  10. 20165320 Java实验三:敏捷开发与XP实践

    实验内容: 敏捷开发与XP实践 一 实验要求: 安装alibaba 插件,解决代码中的规范问题在IDEA中使用工具(Code->Reformate Code)把下面代码重新格式化,再研究一下Co ...