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个棋子的所有 ...
随机推荐
- Git之远程库与本地库交互
对于开发人员而言,有时候在公司干完会到家还得接着干,为了方便同步代码,于是乎,可通过GitHub代码托管平台实现代码云同步. GitHub账号开通.创建远程仓库及初始化等操作此处不做赘述: Git内部 ...
- Swing教程
//用多线程刷新状态 new Thread(new Runnable(){ @Override public void run() { try { for(int i=0;i<1000;i++) ...
- Asp.Net使用加密cookie代替session验证用户登录状态 源码分享
首先 session 和 cache 拥有各自的优势而存在. 他们的优劣就不在这里讨论了. 本实例仅存储用户id于用户名,对于多级权限的架构,可以自行修改增加权限字段 本实例采用vs2010编写 ...
- R5—字符串处理/正则表达式
R通常被用来进行数值计算比较多,字符串处理相对较少,而且关于字符串的函数也不多,用得多的就是substr.strsplit.paste.regexpr这几个了.实际上R关于字符串处理的功能是非常强大的 ...
- Druid.io启用SQL支持
Druid.io的SQL功能虽然在试验阶段,但是也支持了大部分的功能,而且还可以通过 Avatica JDBC查看请求的json,有助于我们理解Druid.io的语法.Druid.io有个比较坑的是, ...
- 20155236 2016-2017-2 《Java程序设计》第五周学习总结
20155236 2016-2017-2 <Java程序设计>第五周学习总结 教材学习内容总结 Java的异常处理是通过5个关键字来实现的:try,catch,throw,throws,f ...
- java后台代码发送邮件
1:安装 eyoumailserversetup 易邮邮件服务器 注册账号 2:安装Foxmail 登录以后会有个还原页面 3:测试 4:java 代码编写 配置文件: mail.host=http ...
- mysql 时间戳
需求:记录表中每条记录创建时间和最新修改时间 一.界面操作 工具:mysql-front 右键添加字段createTime和updateTime,字段类型为timestamp 完成,在表中添加一条新纪 ...
- Python练习-os模块练习-还算是那么回事儿
# 编辑者:闫龙 # 小程序:根据用户输入选择可以完成以下功能: # 创建文件,如果路径不存在,创建文件夹后再创建文件 # 能够查看当前路径 # 在当前目录及其所有子目录下查找文件名包含指定字符串的文 ...
- C# FileStream MemoryStream BufferedStream StreamReader StreamWriter
FileStream读取文件 , array.Length);//读取流中数据把它写到字节数组中file.Close();//关闭流string str =Encoding.Default.GetSt ...