码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 3832 Earth Hour

时间:2014-08-12 02:58:43      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:blog   os   io   for   ar   art   cti   div   

Status
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,
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

 

题目大意 :有n个点 每个点都有一个能够照射到的半径 求在保证1 2 3 点能够被照射到的前提下 最多能关掉几个点

 

感觉这题简直不能更神奇了

将求点转化为求两点间的线段 

先用dijkstra将三个点到各个点的最短路求出 (这里求的是线段数目 网上的题解都是用spfa 无奈学识太浅 先用dij了)

再枚举每个点到 1 2 3点的最短线段数(该点到1 2 3 点如果有线段重复 那必然不是最短)

最后得出结果 n-1-minn

 

 

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll __int64
#define MAXN 1000
#define INF 1000000
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
struct Point
{
    int x,y,r;
};
Point po[230];
int road[230][230];
int d[5][230];
int vis[230];
int n;
void dijkstra(int a)
{
    int i,j,y;
    mem(vis,0);
    for(j=1;j<=n;j++)
    {
        d[a][j]=INF;
    }
    d[a][a]=0;
    for(i=1;i<=n;i++)
    {
        int x,m=INF;
      for(y=1;y<=n;y++) if(!vis[y]&&d[a][y]<m) m=d[a][x=y];
        vis[x]=1;
      for(y=1;y<=n;y++)      
        if(d[a][y]>d[a][x]+road[x][y])        
            d[a][y]=d[a][x]+road[x][y];             
    }
}
int main()
{
    int i,j;
    int t;
    cin>>t;
    while(t--)
    {
        scanf("%d",&n);
        for(i=1;i<=n;i++)        
            scanf("%d%d%d",&po[i].x,&po[i].y,&po[i].r);
        
        for(i=1;i<=n;i++)        
            for(j=1;j<=n;j++)
            {
                if((po[i].x-po[j].x)*(po[i].x-po[j].x)+(po[i].y-po[j].y)*(po[i].y-po[j].y)<=(po[i].r+po[j].r)*(po[i].r+po[j].r))
                    road[i][j]=1;
                else road[i][j]=INF;
            }        
        for(i=1;i<=3;i++) dijkstra(i);        
        int minn=INF;
        for(i=1;i<=n;i++)
        {
            if(d[1][i]+d[2][i]+d[3][i]<minn)
                minn=d[1][i]+d[2][i]+d[3][i];
        }
        if(minn==INF) 
            cout<<"-1"<<endl;
        else 
            cout<<n-minn-1<<endl;
    }
    return 0;
}

  

hdu 3832 Earth Hour,布布扣,bubuko.com

hdu 3832 Earth Hour

标签:blog   os   io   for   ar   art   cti   div   

原文地址:http://www.cnblogs.com/sola1994/p/3906104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!