# pku 2165 gumman

335人阅读 评论(0)

only if coordinate of intersection point in a certain range, including x,y;

that is to "project ", we can get x-coordinate by calculating intersection of a serial of ranges;

next to get two angels, using project, we can solve it on a plane.

Source
#include <iostream>
#include <iomanip>
#include <cmath>
#define N 102
using namespace std;

const double eps = 1e-10;

int n;
struct Window
{
double lbx,lby,rux,ruy;
double z;
};
istream& operator >> (istream& in, Window& win)
{
in>>win.lbx>>win.lby>>win.rux>>win.ruy>>win.z;
return in;
}

Window window[N];
// project to x_o_y
// O(n)
int cal1(double& k)
{
double maxV = 1e15,minV=-1e15 ,tmax,tmin;
for (int I=0; I<n; ++I)
{

if (window[I].z != 0)
{
tmax = window[I].ruy/window[I].z;
tmin = window[I].lby/window[I].z;
maxV = min(maxV,tmax);
minV = max(minV,tmin);
}
if (maxV < minV)
break;
}
if (maxV < minV) return 0;
k = (minV + maxV)/2;
return 1;
}

int cal2(double& x)
{
double maxV = 1e15, minV = -1e15,tmax,tmin;

for (int I=0; I<n-1; ++I)
{
for (int J=I+1; J<n; ++J)
{
if (window[I].z == window[J].z)
{
maxV = -1;
minV = 1;
goto fail;
}
tmin = window[I].lbx - (window[J].rux-window[I].lbx)*window[I].z/(window[J].z - window[I].z);
tmax = window[I].rux - (window[J].lbx-window[I].rux)*window[I].z/(window[J].z - window[I].z);
minV = max(minV,tmin);
maxV = min(maxV,tmax);
if (maxV < minV)goto fail;
}
}
fail:
if (maxV < minV)
return 0;
x = (minV+maxV)/2;
return 1;
}

int caldir(double x, double & k)
{
double rV = 1e15,lV=-1 ,tr,tl;
for (int I=0; I<n; ++I)
{
tr = (window[I].rux - x)/sqrt((window[I].rux - x)*(window[I].rux - x)+window[I].z*window[I].z);
tl = (window[I].lbx - x)/sqrt((window[I].lbx - x)*(window[I].lbx - x)+window[I].z*window[I].z);
rV = min(rV,tr);
lV = max(lV,tl);
}
if (rV < lV-eps)
return 0;
k = (lV+rV)/2/sin(acos((lV+rV)/2));
return 1;
}

void print(double k1,double x, double k2)
{
for (int I=0; I<n; ++I)
{
cout<<(x + k2*window[I].z)<<' '<<window[I].z*k1<<' '<<window[I].z<<endl;
}
}

int main()
{
cin>>n;
for (int I=0; I<n; ++I)
cin>>window[I];
double k1,k2;
double x;
if (cal1(k1)==0 || cal2(x)==0 || caldir(x,k2)==0)
{
cout<<"UNSOLVABLE"<<endl;
}
else
{
cout<<"SOLUTION"<<endl;
cout<<setiosflags(ios::fixed)<<setprecision(6)<<x<<endl;
print(k1,x,k2);
}
return 0;
}


个人资料
等级：
访问量： 4万+
积分： 846
排名： 6万+
文章分类
最新评论