URAL 1489 Points on a Parallelepiped

题意:把一个平面图形转成立体图形,求其中两点的距离。

脑残了,

中间的A,B表示的边看错了。。没有注意边界,没有加EPS。。

改的时候不仔细又wa了好多次。。

思路:一个面一个面判断就行了。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>
#define LL long long
#define DB double

using namespace std;
const DB EPS = 1e-20;
struct cpoint3{
    DB x,y,z;
} a[3];
struct cpoint{
    DB x,y;
    void get(){scanf("%lf%lf",&x,&y);}
} a1[3];
DB A,B,C;
DB dist(cpoint3 a,cpoint3 b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    scanf("%lf%lf%lf",&A,&B,&C);
    a1[0].get();a1[1].get();
    for(int i=0;i<2;i++)
    {
        if(a1[i].x<C-EPS)
        {
            a[i].x = 0;
            a[i].y = a1[i].y-B-C;
            a[i].z = C-a1[i].x;
        }else if(a1[i].x>C+A+EPS)
        {
            a[i].x = A;
            a[i].y = a1[i].y-B-C;
            a[i].z = a1[i].x-A-C;
        }else if(a1[i].y<=B)
        {
            a[i].x = a1[i].x-C;
            a[i].y = B-a1[i].y;
            a[i].z = C;
        }else if(a1[i].y<=B+C)
        {
            a[i].x = a1[i].x-C;
            a[i].y = 0;
            a[i].z = B+C-a1[i].y;
        }else if(a1[i].y<=B+B+C)
        {
            a[i].x = a1[i].x-C;
            a[i].y = a1[i].y - B-C;
            a[i].z = 0;
        }else
        {
            a[i].x = a1[i].x-C;
            a[i].y = B;
            a[i].z = a1[i].y-B-B-C;
        }
    }
    printf("%.16lf\n",dist(a[0],a[1]));
    return 0;
}


你可能感兴趣的:(计算几何)