Review-F-Earth Hour)

Source: Internet
Author: User

F-Earth Hour Time limit:1000 ms Memory limit:65536kb 64bit Io format:% I64d & % i64usubmit status

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 your 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

 351 1 11 4 14 1 12 2 13 3 171 1 14 1 12 4 11 3 13 1 13 3 14 3 161 1 15 1 15 5 13 1 25 3 23 3 1 
 

Sample output

-121 
There are n lamps numbered 1 to n, and the coordinates of each lamp and the lighting range are given. It is required that no. 1, 2, and 3 must be on, and connect them together. What is the maximum number of lights that can be turned off?

The question is to connect 1 and 2 and 3 with the lamp, and connect them with the least lamp.

When three nodes are connected together, there will always be a node, which connects to the shortest of the other three points respectively. Use 1 2 3 to find the shortest path for all other points, respectively, when all vertices in the enumeration are nodes, obtain the smallest value, that is, connect 1 2 3 with the smallest value, and subtract n to obtain the result.


#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define INF 300using namespace std;struct node{    int x , y , r ;} p[300];int mm[300][300] , a[300] ;int dis[300] , vis[300] ;void dij(int n,int u){    int i , j , min1 , k ;    memset(vis,0,sizeof(vis));    for(i = 0 ; i <= n ; i++)        dis[i] = mm[u][i] ;    dis[u] = 0 ;    vis[u] = 1 ;    for(i = 1 ; i <= n ; i++)    {        min1 = INF ;        for(j = 1 ; j <= n ; j++)            if( !vis[j] && dis[j] < min1 )        {            min1 = dis[j] ;            k = j ;        }        if(min1 == INF)            break;        vis[k] = 1 ;        for(j = 1 ; j <= n ; j++)            if( !vis[j] && dis[j] > dis[k] + mm[k][j] )                dis[j] = dis[k] + mm[k][j] ;    }}int main(){    int t , i , j , n , m ;    scanf("%d", &t);    while(t--)    {        scanf("%d", &n);        for(i = 1 ; i <= n ; i++)        {            scanf("%d %d %d", &p[i].x, &p[i].y, &p[i].r);            for(j = 1 ; j <= i ; j++)            {                double l = sqrt( (p[i].x-p[j].x)*(p[i].x-p[j].x)*1.0 + (p[i].y-p[j].y)*(p[i].y-p[j].y)*1.0 );                if(l <= ( p[i].r + p[j].r ))                    mm[i][j] = mm[j][i] = 1 ;                else                    mm[i][j] = mm[j][i] = INF ;            }        }        memset(a,0,sizeof(a));        dij(n,1);        for(i = 1 ; i <= n ; i++)            a[i] += dis[i] ;        dij(n,2);        for(i = 1 ; i <= n ; i++)            a[i] += dis[i] ;        dij(n,3);        for(i = 1 ; i <= n ; i++)            a[i] = n - (a[i] + dis[i] + 1) ;        int max1 = -1 ;        for(i = 1 ; i <= n ; i++)            if( a[i] > max1 )                max1 = a[i] ;        if(max1 < 0 )            printf("-1\n");        else        printf("%d\n", max1);    }    return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.