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个棋子的所有 ...
随机推荐
- 详解 Cookie 纪要(vue.cookie,jquery.cookie简化)
今天看到一篇cookie的文章,写的特别详细,感谢 晚晴幽草轩 的分享,原文链接http://www.jeffjade.com/2016/10/31/115-summary-of-cookie/ 原文 ...
- Java上传文件夹(Jersey)
背景介绍:公司要在CMS系统上为运营人员提供一个功能供运营人员将做好的活动页面上传到阿里云存储上,上传的内容为一个文件夹,文件夹内部有.html网页,JS文件夹下有JS文件,CSS文件夹下有样式表,I ...
- (一)在Lingo中使用集合
1. 在Lingo中使用集合 4.1 集合的基本用法和lingo模型的基本要素 Lingo虽然使用方便,但是如果要解决几万个,几十万个变量的优化问题时,我们总不能一个一个地列出x1,x2,…,x ...
- 轻松使用div模拟select下拉菜单
没有办法,平时不是万不得已我是不喜欢去模拟各类控件的,一个是麻烦,二个是对性能也有些影响,还是原生的来的实在.老板昨天发话,必须模拟赶紧的,老外最喜欢简洁干净的风格,说的貌似都很在理的样子,业务部也是 ...
- 【BZOJ】3456: 城市规划 动态规划+多项式求逆
[题意]求n个点的带标号无向连通图个数 mod 1004535809.n<=130000. [算法]动态规划+多项式求逆 [题解]设$g_n$表示n个点的无向图个数,那么显然 $$g_n=2^{ ...
- C语言入门教程-(3)基本数据类型
1.数据类型 在C语言中,数据类型指的是用于声明不同类型的变量或函数的一个广泛的系统.C语言数据类型可以分为四种: 1.基本类型:它们是算术类型,包括两种类型:整数类型和浮点类型. 2.枚举类型:它们 ...
- 【leetcode 简单】 第七十七题 单词模式
给定一种 pattern(模式) 和一个字符串 str ,判断 str 是否遵循相同的模式. 这里的遵循指完全匹配,例如, pattern 里的每个字母和字符串 str 中的每个非空单词之间存在着双向 ...
- hdu 1495 非常可乐 (广搜)
题目链接 Problem Description 大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为.因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶 ...
- gnuplot生成MySQL QPS图形
1.建立MySQL QPS执行脚本 #!/bin/bash mysqladmin -uroot -p' extended-status -i1|awk \ 'BEGIN{flag=0; print & ...
- 列表选择Spinner
1.只用XML配置来显示列表 在res\values中添加一个arrays.xml 1 <?xml version="1.0" encoding="utf-8&qu ...