Wildleopard had fallen in love with his girlfriend for 20 years. He wanted to end the long match for their love and get married this year. He bought a new house for his family and hired a company to decorate his house. Wildleopard and his fiancee were very satisfied with the postmodern design, except the light bulbs. Varieties of light bulbs were used so that the light in the house differed a lot in different places. Now he asks you, one of his best friends, to help him find out the point of maximum illumination.
To simplify the problem, we can assume each bulb is a point light source and we only need to consider the grid points of the flat floor of the house. A grid point is a point whose coordinates are both integers. The length and the width of house can be considered infinite. Illumination means the amount of light that go through in one unit area. The illumination of a point can be calculated by simply adding the illumination from each source. The illumination from a source can be calculated by the following equation:
Given the position and the luminous intensity of the light bulbs, you are asked to find the maximum illumination on the floor at the grid points.
Input
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 20) which is the number of test cases. And it will be followed by T consecutive test cases.
The first line of each test case contains one integer n(1 <= n <= 100), indicating the number of bulbs of the lamps in the house. The next n lines will contain 4 integers each, Xi, Yi, Zi, Ii, separated by one space, indicating the coordinates and the luminous intensity of the i-th bulb of the lamp. The absolute values of the coordinates do not exceed 100 and Zi is always positive. Ii is a positive integer less than 32768.
Output
Results should be directed to standard output. The output of each test case should be a real number rounded to 0.01, which is the maximum illumination on the floor at the grid points.
Sample Input
3 1 0 0 1 100 4 1 0 1 100 0 1 1 100 -1 0 1 100 0 -1 1 100 4 1 0 100 10000 0 1 100 10000 -1 0 100 10000 0 -1 100 10000
Sample Output
100.00 147.43 4.00
Author: GUAN, Yao
Source: The 5th Zhejiang Provincial Collegiate Programming Contest
// 1867310 2009-05-13 08:56:13 Time Limit Exceeded 2976 C++ 1001 0 Wpl
// 1867326 2009-05-13 09:07:21 Accepted 2976 C++ 470 188 Wpl
#include < iostream >
#define MAX 102
#include < cmath >
using namespace std;
typedef struct node
{
double x,y,z;
double I;
}Point;
Point data[MAX];
int t,n;
double MM;
void Init()
{
int i;
scanf( " %d " , & n);
for (i = 0 ;i < n;i ++ )
scanf( " %lf%lf%lf%lf " , & data[i].x, & data[i].y, & data[i].z, & data[i].I);
}
/* double GetI(Point p,int x,int y)
{
double dis=pow((p.z*p.z+(p.x-x)*(p.x-x)+(p.y-y)*(p.y-y)),1.5);
double e;
e=p.I*p.z/dis;
return e;
} */
double GetDis(Point p, int i, int j)
{
return p.z * p.z + (p.x - i) * (p.x - i) + (p.y - j) * (p.y - j);
}
void Process()
{
int i,j,k;
MM =- 1.0 ;
double sum,dis;
for (i =- 100 ;i <= 100 ;i ++ )
for (j =- 100 ;j <= 100 ;j ++ )
{
sum = 0 ;
for (k = 0 ;k < n;k ++ )
{
dis = GetDis(data[k],i,j);
sum += data[k].I * data[k].z / (dis * sqrt(dis));
}
if (sum > MM)
MM = sum;
}
printf( " %0.2lf\n " ,MM);
}
int main()
{
scanf( " %d " , & t);
while (t -- )
{
Init();
Process();
}
return 0 ;
}