gym 100531 三维几何+搜索
精度有点毒, 其实可以不用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 三维几何+搜索的更多相关文章
- hdu 1240:Asteroids!(三维BFS搜索)
Asteroids! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 5839(三维几何)
Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度
原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...
- Codeforces Gym 100231F Solitaire 折半搜索
Solitaire 题目连接: http://codeforces.com/gym/100231/ Description 给你一个8*8棋盘,里面有4个棋子,每个棋子可以做一下某个操作之一: 1.走 ...
- GYM 100608G 记忆化搜索+概率 2014-2015 Winter Petrozavodsk Camp, Andrew Stankevich Contest 47 (ASC 47)
https://codeforces.com/gym/100608 题意: 两个人玩游戏,每个人有一个长为d的b进制数字,两个人轮流摇一个$[0,b-1]$的骰子,并将选出的数字填入自己的d个空位之中 ...
- POJ 2177 Ghost Busters(三维几何)
Description The famous Ghost Busters team has decided to upgrade their Ectomobile (aka Ecto-1) with ...
- HDU 4617 Weapon(三维几何)
Problem Description Doctor D. are researching for a horrific weapon. The muzzle of the weapon is a c ...
- hdu 4617 Weapon【异面直线距离——基础三维几何】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4617 Weapon Time Limit: 3000/1000 MS (Java/Others) ...
- kuangbin专题总结一 简单搜索
A - 棋盘问题:在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有 ...
随机推荐
- linux下安装python和pip
注意:不要轻易去卸载原有的python环境,因为有些软件是依赖他的 一:安装前,先将依赖环境一并安装,避免后面重复编译 [root@redhat2 bin]# yum install gcc g++ ...
- Git之版本回退及回滚
应用场景 当开发某个项目时,会有多次提交记录,如A版本àB版本àC版本,假如目前处于C版本状态,我想回退到A版本,该如何操作:而当回退到A版本后,我又想回滚到B版本,又该如何操作,见下文分解!
- core EFCore 开始尝试
准备工作: 工程:core + console 引用包: Install-Package Microsoft.EntityFrameworkCore Install-Package Microsoft ...
- hdu 1495 非常可乐 (广搜)
题目链接 Problem Description 大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为.因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶 ...
- JavaScript 实用技巧和写法建议
1.前言 从大学到现在,接触前端已经有几年了,感想方面,就是对于程序员而言,想要提高自己的技术水平和编写易于阅读和维护的代码,我觉得不能每天都是平庸的写代码,更要去推敲,去摸索和优化代码,总结当中的技 ...
- Python标准库笔记(10) — itertools模块
itertools 用于更高效地创建迭代器的函数工具. itertools 提供的功能受Clojure,Haskell,APL和SML等函数式编程语言的类似功能的启发.它们的目的是快速有效地使用内存, ...
- 如何更方便的查看Linux内核代码的更新记录【转】
转自:http://blog.csdn.net/lee244868149/article/details/44302819 Linux内核的更新非常的快,如何快速的了解这些更新呢?最一般的办法就是把新 ...
- aarch64_g1
GAPDoc-1.5.1-12.fc26.noarch.rpm 2017-02-14 07:37 1.0M fedora Mirroring Project GAPDoc-latex-1.5.1-12 ...
- MySQL主从复制-指定数据库复制
在/etc/my.cnf添加需要进行同步的数据库信息 #需要进行同步的数据库 #replicate-do-db=custmgr #replicate-do-db=sdata #replicate-ig ...
- clog,cout,cerr 输出机制
clog:控制输出,使其输出到一个缓冲区,这个缓冲区关联着定义在 <cstdio> 的 stderr. cerr:强制输出刷新,没有缓冲区. cout:控制输出,使其输出到一个缓冲区,这个 ...