题解

把直线的斜率分解成二维,也就是随着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的更多相关文章

  1. 【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, ...

  2. 【POJ】1067 取石子游戏(博弈论)

    Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...

  3. 【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$都是偶数啦~ ...

  4. 【POJ】【2104】区间第K大

    可持久化线段树 可持久化线段树是一种神奇的数据结构,它跟我们原来常用的线段树不同,它每次更新是不更改原来数据的,而是新开节点,维护它的历史版本,实现“可持久化”.(当然视情况也会有需要修改的时候) 可 ...

  5. 【POJ】1222 EXTENDED LIGHTS OUT

    [算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...

  6. 【POJ】2892 Tunnel Warfare

    [算法]平衡树(treap) [题解]treap知识见数据结构 在POJ把语言从G++换成C++就过了……??? #include<cstdio> #include<algorith ...

  7. 【POJ】【1637】Sightseeing tour

    网络流/最大流 愚人节快乐XD 这题是给一个混合图(既有有向边又有无向边),让你判断是否有欧拉回路…… 我们知道如果一个[连通]图中每个节点都满足[入度=出度]那么就一定有欧拉回路…… 那么每条边都可 ...

  8. 【poj】1001

    [题目] ExponentiationTime Limit: 500MS Memory Limit: 10000KTotal Submissions: 123707 Accepted: 30202De ...

  9. 【POJ】3070 Fibonacci

    [算法]矩阵快速幂 [题解] 根据f[n]=f[n-1]+f[n-2],可以构造递推矩阵: $$\begin{vmatrix}1 & 1\\ 1 & 0\end{vmatrix} \t ...

随机推荐

  1. python中__init__()、__new__()、__call__()、__del__()用法

    关于__new__()的用法参考: http://www.myhack58.com/Article/68/2014/48183.htm 正文: 一.__new__()的用法: __new__()是在新 ...

  2. Java基础-Collection子接口之Set接口

    Java基础-Collection子接口之Set接口 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 学习Collection接口时,记得Collection中可以存放重复元素,也可 ...

  3. 转:UIViewController中各方法调用顺序及功能详解

    UIViewController中loadView, viewDidLoad, viewWillUnload, viewDidUnload, viewWillAppear, viewDidAppear ...

  4. Eclipse安卓插件安装

    首先说明下载的ADT专门真安卓开发的Eclipse下载下来后就集成了可以直接使用了 但是使用j2EE版本的Eclipse就需要安装插件支持安卓开发了 首先下载ADT Eclipse安卓插件 下载完成后 ...

  5. @Controller,@Service,@Repository,@Component详解

    @Controller 用来表示一个web控制层bean,如SpringMvc中的控制器. @Service 用来表示一个业务层bean. @Repository 用来表示一个持久层bean,即数据访 ...

  6. Spring Enable*高级应用及原理

    Enable* 之前的文章用到了一些Enable*开头的注解,比如EnableAsync.EnableScheduling.EnableAspectJAutoProxy.EnableCaching等, ...

  7. jQuery基础之二(操作标签)

    一:样式操作 addClass();// 添加指定的CSS类名. removeClass();// 移除指定的CSS类名. hasClass();// 判断样式存不存在 toggleClass();/ ...

  8. Go net/http获取body中json格式数据

    Go net/http获取body中json格式数据 package main import ( "encoding/json" "fmt" "io/ ...

  9. Multiple HTTPS Bindings IIS 7 Using appcmd

    http://toastergremlin.com/?p=308 Sometimes when using a wildcard SSL or Unified Communications Certi ...

  10. 芒果TV 视频真实的地址获取

    # coding=utf-8 import requests import json import re import os import urlparse import random vid = r ...