zoukankan      html  css  js  c++  java
  • zoj 2976 Light Bulbs(暴力枚举)

    Light Bulbs

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    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, XiYi,ZiIi, 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

    //本来以为是函数超时,结果是因为多组数据的读入而超时的
    #include <iostream>
    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    int t,n;
    int x[105],y[105],z[105],l[105];
    double ans;
    int main()
    {
        scanf("%d",&t);
        for(;t>0;t--)
        {
            scanf("%d",&n);
            for(int i=1;i<=n;i++)
                scanf("%d%d%d%d",&x[i],&y[i],&z[i],&l[i]);
            ans=0;
            for(int i=-100;i<=100;i++)//数据小,可以纯暴力
             for(int j=-100;j<=100;j++)
            {
                double sum=0;
                for(int k=1;k<=n;k++)
                {
                    //double R=sqrt((x[k]-i)*(x[k]-i)+(y[k]-j)*(y[k]-j)+z[k]*z[k]);
                    double R=sqrt(pow(x[k]-i,2)+pow(y[k]-j,2)+z[k]*z[k]);
                    //if (i==0 && j==0) printf("%lf
    ",(double)R);
                    sum=sum+l[k]/(R*R*R)*z[k];
                }
                //ans=ans<sum?sum:ans;
                ans=max(ans,sum);
              //本来以为是因为用了数学函数所以超时原来是以为多组数据的问题,去掉whil(~scanf("%d",&t))就ac了
            }
            printf("%.2lf
    ",ans);
        }
    
        return 0;
    }
  • 相关阅读:
    Build 2016: 发布明天的云创新来服务今天的开发者
    微软在Build 2016开发者大会中发布 “认知服务”,牛津计划有正式名字啦!
    流行开源软件云上体验周 ——一种正确的云上开源软件体验姿势!
    让每个人都体验到来自云端的智能
    hdmap相关单词
    绝对误差和相对误差的定义
    高速公路之匝道
    hdmap相关
    虚拟参考站(VRS)
    matlab之结构体数组struct
  • 原文地址:https://www.cnblogs.com/stepping/p/6406758.html
Copyright © 2011-2022 走看看