HDU 3822 Earth Hour

Earth Hour

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 1532    Accepted Submission(s): 616


Problem Description
Earth Hour is an annual international event created by the WWF (World Wide Fund for Nature/World Wildlife Fund), held on the last Saturday of March, that asks households and businesses to turn off their non-essential lights and electrical appliances for one hour to raise awareness towards the need to take action on climate change. 
To respond to the event of this year, the manager of Hunan University campus decides to turn off some street lights at night. Each street light can be viewed as a point in a plane, which casts flash in a circular area with certain radius.
What's more, if two illuminated circles share one intersection or a point, they can be regarded as connected.
Now the manager wants to turn off as many lights as possible, guaranteeing that the illuminated area of the library, the study room and the dormitory are still connected(directly or indirectly). So, at least the lights in these three places will not be turned off.
 

Input
The first line contains a single integer T, which tells you there are T cases followed.
In each case:
The first line is an integer N( 3<=N<=200 ), means there are N street lights at total.
Then there are N lines: each line contain 3 integers, X,Y,R,( 1<=X,Y,R<=1000 ), means the light in position(X,Y) can illuminate a circle area with the radius of R. Note that the 1st of the N lines is corresponding to the library, the 2nd line is corresponding to the study room, and the 3rd line is corresponding to the dorm.
 

Output
One case per line, output the maximal number of lights that can be turned off.
Note that if none of the lights is turned off and the three places are still not connected. Just output -1.
 

Sample Input
  
  
3 5 1 1 1 1 4 1 4 1 1 2 2 1 3 3 1 7 1 1 1 4 1 1 2 4 1 1 3 1 3 1 1 3 3 1 4 3 1 6 1 1 1 5 1 1 5 5 1 3 1 2 5 3 2 3 3 1
 

Sample Output
  
  
-1 2 1
 

Source
解题思路:给定一个图上的一些坐标的位置和他们的半径,如果两个点半径辐射到的圆有相交就说这两个点是连通的,问最多可以删掉几个点使得1,2,3号点连通,对1,2,3号点分别做一次最短路,求一点使得三点到这一点的距离之和最小,然后用总点数减去这个和再减1就是答案
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define Inf 99999999
using namespace std;
int map[205][205],dis[3][205];
inline double Dis(int x1,int y1,int x2,int y2)
{
    return sqrt((x1-x2)*(x1-x2)*1.0+(y1-y2)*(y1-y2)*1.0);
}
void dij(int s,int n,int *dis)
{
    int i,j,k,flag,temp;
    bool visit[205];
    memset(visit,false,sizeof(visit));
    visit[s]=true;
    for(i=1;i<=n;i++)
        dis[i]=map[s][i];
    for(i=1;i<n;i++)
    {
        temp=Inf;flag=0;
        for(j=1;j<=n;j++)
        {
            if(temp>dis[j]&&!visit[j])
            {
                temp=dis[j];
                flag=j;
            }
        }
        if(!flag)
            break;
        visit[flag]=true;
        for(k=1;k<=n;k++)
            if(dis[k]>dis[flag]+map[flag][k]&&!visit[k])
                dis[k]=dis[flag]+map[flag][k];
    }
}
int main()
{
    int i,j,t,p,x[205],y[205],r[205],sum;
    scanf("%d",&t);
    while(t--)
    {
        sum=Inf;
        for(i=0;i<205;i++)
            for(j=0;j<205;j++)
                map[i][j]=(i==j?0:Inf);
        scanf("%d",&p);
        for(i=1;i<=p;i++)
            scanf("%d%d%d",&x[i],&y[i],&r[i]);
        for(i=1;i<=p;i++)
            for(j=1;j<=p;j++)
            {
                if(i==j)
                    continue;
                if(Dis(x[i],y[i],x[j],y[j])<=r[i]+r[j])
                    map[i][j]=map[j][i]=1;
            }
        dij(1,p,dis[0]);
        dij(2,p,dis[1]);
        dij(3,p,dis[2]);
        for(i=1;i<=p;i++)
            if(dis[0][i]!=Inf&&dis[1][i]!=Inf&&dis[2][i]!=Inf)
                sum=min(sum,dis[0][i]+dis[1][i]+dis[2][i]);
        if(sum==Inf)
            printf("-1\n");
        else
            printf("%d\n",p-sum-1);
    }
    return 0;
}


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值