【ZOJ - 2976】Light Bulbs (枚举,暴力)

版权声明:欢迎学习我的博客,希望ACM的发展越来越好~ https://blog.csdn.net/qq_41289920/article/details/88176390

题干:

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:

, where E is the illumination of the point, I is the luminous intensity of the source, R is the distance between the source and the point and i is the angle between the normal of the plane and the light to the point.

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

题目大意:

   告诉你n个光源的光强和光源的三维坐标,告诉你一个光源投射到地面某一个坐标时,光强的计算公式。告诉你最终地面某一坐标上的光强,就是各光源投影过来的代数和。求地面整点坐标可以达到的最大光强。

解题报告:

   直接暴力就行。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const int MAX = 2e5 + 5;
const int INF = 0x3f3f3f3f;
int a[MAX];
int num,maxx,maxy,minx,miny;
struct Node {
	int x,y,z,qd;
} p[MAX];
int main() {
	int t;
	cin>>t;
	while(t--) {
		scanf("%d",&num);
		maxx=maxy=-INF;
		minx=miny=INF;
		for(int i = 1; i<=num; i++) {
			scanf("%d%d%d%d",&p[i].x,&p[i].y,&p[i].z,&p[i].qd);
			maxx = max(maxx,p[i].x);maxy = max(maxy,p[i].y);
			minx = min(minx,p[i].x);miny = min(miny,p[i].y);
		}
		double maxans = 0,ans = 0;
		for(int i = minx; i<=maxx; i++) {
			for(int j = miny; j<=maxy; j++) {
				maxans  = 0;
				for(int k = 1; k<=num; k++) {
					double dist = (p[k].x-i)*(p[k].x-i) + (p[k].y-j)*(p[k].y-j) +p[k].z*p[k].z;
					maxans += (double)p[k].qd /dist * (p[k].z)/sqrt(dist);
				}
				ans = max(maxans,ans);
			}
		}
		printf("%.2f\n",ans);
	}
	return 0 ;
}

猜你喜欢

转载自blog.csdn.net/qq_41289920/article/details/88176390