2015
04-13

# Earth Hour

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.

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.

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.

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

-1
2
1

/*

竟然用的这个方法过的：
先算出3个点分别到其它各个点的距离，然后遍历所

实在不明白，为什么这样能ac。比如：这样得出的

2012-07-25
*/

#include"stdio.h"
#include"math.h"
#include"string.h"
int queue[5555];

struct A
{
int x,y;
int r;
int total;
int mem[222];
}E[222];
int n;

int dis[222];
int dis_1[222];
int dis_2[222];
int dis_3[222];

int MIN(int a,int b)
{
return a>b?b:a;
}

void SPFA(int s)
{
int key,k;
int i;
int hash[222];
int temp;

for(i=1;i<=n;i++)	dis[i]=1111111;
dis[s]=0;

memset(hash,0,sizeof(hash));
k=0;
key=1;
queue[0]=s;
hash[s]=1;
while(k<key)
{
for(i=0;i<E[queue[k]].total;i++)
{
temp=dis[queue[k]]+1;
if(temp<dis[E[queue[k]].mem[i]])
{
dis[E[queue[k]].mem[i]]=temp;
if(!hash[E[queue[k]].mem[i]])
{
hash[E[queue[k]].mem[i]]=1;
queue[key++]=E[queue[k]].mem[i];
}
}
}
hash[queue[k]]=0;
k++;
}
}
int main()
{
int T;
int i,l;
int t1,t2;
int min;

scanf("%d",&T);
while(T--)
{
scanf("%d",&n);

for(i=1;i<=n;i++)	scanf("%d%d%d",&E[i].x,&E[i].y,&E[i].r);
for(i=1;i<=n;i++)
{
E[i].total=0;
for(l=1;l<=n;l++)
{
if(i==l)	continue;
t1=abs(E[i].x-E[l].x)*abs(E[i].x-E[l].x)+abs(E[i].y-E[l].y)*abs(E[i].y-E[l].y);
t2=(E[i].r+E[l].r)*(E[i].r+E[l].r);
if(t2>=t1)	E[i].mem[E[i].total++]=l;
}
}

SPFA(1);
for(i=1;i<=n;i++)	dis_1[i]=dis[i];
SPFA(2);
for(i=1;i<=n;i++)	dis_2[i]=dis[i];
SPFA(3);
for(i=1;i<=n;i++)	dis_3[i]=dis[i];

min=111111;
for(i=1;i<=n;i++)	min=MIN(min,dis_1[i]+dis_2[i]+dis_3[i]);

if(min==111111)	printf("-1\n");
else			printf("%d\n",n-min-1);
}
return 0;
}

1. 对于这种即兴演讲，经常会有思维跳跃和转换，也会有些玩笑话。字幕并不以体现出这些，也体现不出语气、思维层次和结构。如果都逐句话翻译，反而会对理解内容产生一种混乱的感觉，不利于理解。看了就好！关注信息中有价值的东西，尽量不要受信息形式的影响，那样可惜了。谢谢

2. 5.1处，反了；“上一个操作符的优先级比操作符ch的优先级大，或栈是空的就入栈。”如代码所述，应为“上一个操作符的优先级比操作符ch的优先级小，或栈是空的就入栈。”