【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 ...
随机推荐
- Linux设备驱动之Ioctl控制
大部分驱动除了需要具备读写设备的能力之外,还需要具备对硬件控制的能力. 一.在用户空间,使用ioctl系统调用来控制设备,原型如下: int ioctl(int fd,unsigned long cm ...
- 前端案例分享(一):CSS+JS实现流星雨动画
目录 引言 1.效果图 2.源码 3.案例解析 4.小问题 5.结语 引言 平常会做一些有意思的小案例练手,通常都会发到codepen上,但是codepen不能写分析. 所 ...
- poj 2185 Milking Grid
Milking Grid http://poj.org/problem?id=2185 Time Limit: 3000MS Memory Limit: 65536K Descript ...
- noi题库(noi.openjudge.cn) 3.9数据结构之C++STL T1——T2
T1 1806:词典 描述 你旅游到了一个国外的城市.那里的人们说的外国语言你不能理解.不过幸运的是,你有一本词典可以帮助你. 输入首先输入一个词典,词典中包含不超过100000个词条,每个词条占据一 ...
- IIS Media Service: Channel 小结
IIS Media Service 对Channel的Schema可以在浏览器中输入http://{0}:{1}/services/smoothstreaming/publishingpoints.i ...
- HDU1693 Eat the Trees(zerojudge a228)
传送门: https://zerojudge.tw/ShowProblem?problemid=a228 http://acm.hdu.edu.cn/showproblem.php?pid=1693 ...
- laravel更新某一个或几个字段
//更新会员状态status $ary_where = array(); $ary_where[] = ['id', '=', $int_id]; $result = $this->obj_ad ...
- POJ 2230 Watchcow && USACO Watchcow 2005 January Silver (欧拉回路)
Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to wal ...
- 存储过程简单Demo
--创建存储过程 delimiter // create procedure p1() begin end // --调用存储过程 call p1(); --删除存储过程 drop procedure ...
- 【codeforces】【比赛题解】#931 CF Round #468 (Div. 2)
因为太迟了,所以没去打. 后面打了Virtual Contest,没想到拿了个rank 3,如果E题更快还能再高,也是没什么想法. [A]Friends Meeting 题意: 在数轴上有两个整点\( ...