哈理工2015 暑假訓練賽 zoj 2976 Light Bulbs,zojbulbs
Light BulbsTime Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmitStatusPracticeZOJ 2976Description
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, 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
310 0 1 10041 0 1 1000 1 1 100-1 0 1 1000 -1 1 10041 0 100 100000 1 100 10000-1 0 100 100000 -1 100 10000
Sample Output
100.00147.434.00這個大水題啊 賽後迅速1 a 不過有啥用啊 ~ 當時因為少看了一個條件,他給定了枚舉範圍 ,那麼這就好辦了…… 只需枚舉-100 到100 矩形地區內的點即可另外注意座標系建立的時候不能使下標為負,那麼我們就可以把原點建在(-100,100)上。然後三重迴圈搞定。
#include<iostream>#include<sstream>#include<algorithm>#include<cstdio>#include<string.h>#include<cctype>#include<string>#include<cmath>#include<vector>#include<stack>#include<queue>#include<map>#include<set>using namespace std;const int INF=102;double cnt[2*INF+5][2*INF+5];double A(double x){ return x*x;}double dis(double x1,double y1,double z1,double x2,double y2,double z2 ){ return sqrt(A(x1-x2)+A(y1-y2)+A(z1-z2));}int main(){ int t;cin>>t; while(t--) { memset(cnt,0,sizeof(cnt)); int n;cin>>n; for(int i=0;i<n;i++) { double x,y,z,I;scanf("%lf%lf%lf%lf",&x,&y,&z,&I); for(int i=0;i<=2*INF;i++) { for(int j=0;j<=2*INF;j++) { double R=dis(x,y,z,i-INF,j-INF,0); double t=z/R; cnt[i][j]+=(I/(R*R))*t; } } } double ans=-1; for(int i=0;i<=2*INF;i++) { for(int j=0;j<=2*INF;j++) { //cout<<cnt[i][j]<<" "; ans=max(cnt[i][j],ans); } } printf("%.2lf\n",ans); } return 0;}/*2341-102 -102 3*/
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。