精度有点毒, 其实可以不用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. Elasticsearch5.2.0部署过程的坑

    今天开工,在看ES时候发现前几天已经发布了5.2.0,就安装了一下,岂料安装完一直启动不了,可以说是一个bug. 报错: ERROR: bootstrap checks failed system c ...

  2. java.lang.System.arraycopy() 与java.util.Arrays.copyOf()的区别

    java.lang.System.arraycopy() 与java.util.Arrays.copyOf()的区别 一.java.lang.System.arraycopy() 该方法的声明: /* ...

  3. js中call与apply的区别以及使用~

    今天看了一下call与apply的区别~~ <!DOCTYPE html> <html> <head> <title>testCall</titl ...

  4. Centos7网络配置(VMware)

    在VM虚拟机上装了Centos7,想要用xshell5连接操作,配置网络花了整整一个上午的时间,真是心酸. 登陆后,使用命令 ip addr查看了本机的网络 可以看到我的网络配置文件是ens33, 使 ...

  5. Linux基础-网络配置

    任务目标:临时配置网络ip,网关,DNS,然后重启network:写配置文件永久保存网络配置 临时配置ens33网卡IP地址为192.168.30.99,查看更改完的ifconfig信息: 重新启动n ...

  6. erp前端项目总结

    目录 一.项目目录(vue-cli2) 二.开发实践 (一) 权限 (二) 各组件间传递数据 (四) 路由 (七) 组织部门业务员三级联动 (八) 优化性能,手动绑定下拉框数据 (九) 验证 (十) ...

  7. UNIX环境高级编程 第14章 高级I/O

    这一章涉及很多概念和函数,包括:非阻塞I/O.记录锁.I/O复用.异步I/O.readv和writev函数以及内存映射. 非阻塞I/O 在Unix中,可以将系统调用分为两种,一种是“低速”系统调用,另 ...

  8. 关于注入抽象类报could not autowire field的问题

    昨天工作中遇到了一个很奇葩的问题,之前一直都没考虑过抽象类这块,一直用的注入接口实现类: 先看下错误: 因为在类中注入了一个抽象类,之前只有一个继承子类,所以没问题,这里要说一下抽象类的实例化: 抽象 ...

  9. linux arm mmu基础【转】

    转自:http://blog.csdn.net/xiaojsj111/article/details/11065717 ARM MMU页表框架 先上一张arm mmu的页表结构的通用框图(以下的论述都 ...

  10. cocos2dx中调用TinyXml读取xml配置文件 || cocos2d-x 中跨平台tinyxml读取xml文件方式

    TiXmlDocument *doc = newTiXmlDocument; #if (CC_TARGET_PLATFORM ==CC_PLATFORM_ANDROID) //Android平台tin ...