sgu 198 分类: sgu 2015-05-23 23:06 28人阅读 评论(0) 收藏


其实我并不会做,看了大神的题解才会的。
所以也没有什么好说的,毕竟计算几何。。。


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<iostream>
#include<algorithm>

const int MAXN = 305;const double eps = 1e-10;
struct Node{double x,y;Node(double x = 0,double y = 0):x(x),y(y){}};
typedef Node Vec;
Vec operator -(const Node &a, const Node &b){return Vec(b.x-a.x,b.y-a.y);}

int n;
Node p[MAXN]; double r[MAXN], pix[MAXN];

bool g[MAXN][MAXN];
double h[MAXN][MAXN];

bool flag[MAXN];
double min[MAXN];
std::queue<int>line;
int in[MAXN];

int dcmp(double u)
{
    if(fabs(u) < eps)return 0;
    return u > 0 ? 1 : -1;
}
double Calcu(Vec p,Vec q)
{
    return atan2(p.x*q.y-p.y*q.x,p.x*q.x+p.y*q.y);
}

bool SPFA()
{
    for(int i = 1; i <= n; i++)
        line.push(i), flag[i] = true;

    while(!line.empty())
    {
        int t = line.front();
        line.pop(), flag[t] = false;

        for(int i = 1; i <= n; i++)
            if(g[t][i] == true)
                if(dcmp(min[t] + h[t][i] - min[i]) < 0)
                {
                    min[i] = min[t] + h[t][i];
                    if(flag[i] == false)
                    {
                        line.push(i), flag[i] = true;
                        if(++in[i] > n) return true;
                    }
                }
    }
    return false;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("sgu198.in","r",stdin);
    freopen("sgu198.out","w",stdout);
#endif

    std::cin >> n;
    for(int i = 1; i <= n; i++)
        std::cin >> p[i].x >> p[i].y >> r[i];
    std::cin >> p[0].x >> p[0].y >> r[0];

    for(int i = 1; i <= n; i++)
        r[i] += r[0], pix[i] = atan2(p[i].y-p[0].y,p[i].x-p[0].x);

    for(int i = 1; i <= n; i++)
        for(int j = i+1; j <= n; j++)
            if(dcmp(pow(p[i].x-p[j].x,2)+pow(p[i].y-p[j].y,2)-pow(r[i]+r[j],2)) < 0)
                g[i][j] = true, h[i][j] = Calcu(p[i]-p[0],p[j]-p[0]), g[j][i] = true, h[j][i] = -h[i][j];   

    if(SPFA()) std::cout << "NO" << std::endl;
    else    std::cout << "YES" << std::endl;


#ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
#endif
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2015-05-23 23:06  <Dash>  阅读(184)  评论(0编辑  收藏  举报