【POJ】2165.Gunman
题解
把直线的斜率分解成二维,也就是随着z的增加x的增量和y的增量
我们发现一条合法直线向上移一点一定能碰到一条横线
知道了这条横线可以算出y的斜率
我们旋转一下,让这条横线碰到两条竖线,就可以算出x的斜率,进而判断直线在不在平面内
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
//#define ivorysi
#define MAXN 105
#define eps 1e-8
using namespace std;
typedef long long int64;
typedef double db;
struct plane{
double x[2],y[2],z;
}pl[MAXN];
struct Point{
double x,y;
}P[MAXN * 4];
int N,cnt;
db yk,xk,sx;
void Init() {
scanf("%d",&N);
for(int i = 1 ; i <= N ; ++i) {
scanf("%lf%lf%lf%lf%lf",&pl[i].x[0],&pl[i].y[0],&pl[i].x[1],&pl[i].y[1],&pl[i].z);
}
}
void Solve() {
for(int i = 1 ; i <= N ; ++i) {
for(int r = 0 ; r <= 1 ; ++r) {
db k = pl[i].y[r] / pl[i].z;
cnt = 0;
bool flag = 0;
for(int j = 1 ; j <= N ; ++j) {
if(pl[j].z * k > pl[j].y[1] + eps || pl[j].z * k < pl[j].y[0] - eps) goto succ;
for(int c = 0 ; c <= 1 ; ++c) {
P[++cnt] = (Point){pl[j].x[c],pl[j].z};
}
}
yk = k;
for(int j = 1 ; j <= cnt ; ++j) {
for(int h = j + 1 ; h <= cnt ; ++h) {
if(P[j].y == P[h].y) continue;
flag = 1;
k = (P[j].x - P[h].x) / (P[j].y - P[h].y);
if(P[j].x == P[h].x) k = 0;
sx = P[j].x - P[j].y * k;
for(int l = 1 ; l <= N ; ++l) {
db tmp = sx + k * pl[l].z;
if(tmp < pl[l].x[0] - eps || tmp > pl[l].x[1] + eps) {flag = 0;break;}
}
if(flag) {
xk = k;goto succ;
}
}
}
succ:;
if(flag) {
puts("SOLUTION");
printf("%.6f\n",sx);
for(int i = 1 ; i <= N ; ++i) {
printf("%.6f %.6f %.6f\n",sx + xk * pl[i].z,yk * pl[i].z,pl[i].z);
}
return;
}
}
}
puts("UNSOLVABLE");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Init();
Solve();
}
【POJ】2165.Gunman的更多相关文章
- 【POJ】1704 Georgia and Bob(Staircase Nim)
Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...
- 【POJ】1067 取石子游戏(博弈论)
Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...
- 【BZOJ】【1986】【USACO 2004 Dec】/【POJ】【2373】划区灌溉
DP/单调队列优化 首先不考虑奶牛的喜欢区间,dp方程当然是比较显然的:$ f[i]=min(f[k])+1,i-2*b \leq k \leq i-2*a $ 当然这里的$i$和$k$都是偶数啦~ ...
- 【POJ】【2104】区间第K大
可持久化线段树 可持久化线段树是一种神奇的数据结构,它跟我们原来常用的线段树不同,它每次更新是不更改原来数据的,而是新开节点,维护它的历史版本,实现“可持久化”.(当然视情况也会有需要修改的时候) 可 ...
- 【POJ】1222 EXTENDED LIGHTS OUT
[算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...
- 【POJ】2892 Tunnel Warfare
[算法]平衡树(treap) [题解]treap知识见数据结构 在POJ把语言从G++换成C++就过了……??? #include<cstdio> #include<algorith ...
- 【POJ】【1637】Sightseeing tour
网络流/最大流 愚人节快乐XD 这题是给一个混合图(既有有向边又有无向边),让你判断是否有欧拉回路…… 我们知道如果一个[连通]图中每个节点都满足[入度=出度]那么就一定有欧拉回路…… 那么每条边都可 ...
- 【poj】1001
[题目] ExponentiationTime Limit: 500MS Memory Limit: 10000KTotal Submissions: 123707 Accepted: 30202De ...
- 【POJ】3070 Fibonacci
[算法]矩阵快速幂 [题解] 根据f[n]=f[n-1]+f[n-2],可以构造递推矩阵: $$\begin{vmatrix}1 & 1\\ 1 & 0\end{vmatrix} \t ...
随机推荐
- Python中hashlib模块
介绍hashlib hashlib 是一个提供了一些流行的hash算法的 Python 标准库.其中所包括的算法有 md5, sha1, sha224, sha256, sha384, sha512. ...
- Spark记录-Scala介绍
Scala是可扩展语言的缩写,是一种混合功能编程语言. 它由Martin Odersky创建. Scala顺利整合面向对象和函数式语言的功能. Scala被编译后在Java虚拟机上运行. 许多现有公司 ...
- 64位Ubuntu 安装scrapy遇到的问题
这两天准备开始学习Python爬虫,安装scrapy框架后出现 Traceback (most recent call last): File "/usr/local/bin/scrapy& ...
- 6.redis的分布式锁
https://www.cnblogs.com/linjiqin/p/8003838.html
- [SDOI2016 Round1] 数字配对
COGS 2221. [SDOI2016 Round1] 数字配对 http://www.cogs.pro/cogs/problem/problem.php?pid=2221 ★★★ 输入文件:m ...
- mysql自学路线
入门: -Head First:PHP & MySQL.Lynn Beighley -MySQL必知必会 -MySQL5.5从零开始学.刘增杰 -MYSQL完全手册 (the Complete ...
- Grafana关键词
The open platform for beautiful analytics and monitoring. data source.panels.apps.dashboards. Organi ...
- python 日期时间处理
# 获取日期: import datetime #调用事件模块 today =datetime.date.today() #获取今天日期 deltadays =datetime.timedelta(d ...
- 【转】java格式化输出 printf 例子
[转]java格式化输出 printf 例子 转自http://www.cnblogs.com/TankMa/archive/2011/08/20/2146913.html#undefined imp ...
- J - Clairewd’s message HDU - 4300(扩展kmp)
题目链接:https://cn.vjudge.net/contest/276379#problem/J 感觉讲的很好的一篇博客:https://subetter.com/articles/extend ...