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[],y[],z[],l[];
double ans;
int main()
{
scanf("%d",&t);
for(;t>;t--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d%d%d",&x[i],&y[i],&z[i],&l[i]);
ans=;
for(int i=-;i<=;i++)//数据小,可以纯暴力
for(int j=-;j<=;j++)
{
double sum=;
for(int k=;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,)+pow(y[k]-j,)+z[k]*z[k]);
//if (i==0 && j==0) printf("%lf\n",(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\n",ans);
} return ;
}

zoj 2976 Light Bulbs(暴力枚举)的更多相关文章

  1. 哈理工2015 暑假训练赛 zoj 2976 Light Bulbs

    MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu SubmitStatusid=14946">Practice ...

  2. [ACM] ZOJ 3816 Generalized Palindromic Number (DFS,暴力枚举)

    Generalized Palindromic Number Time Limit: 2 Seconds      Memory Limit: 65536 KB A number that will ...

  3. HDU 4770 Lights Against Dudely 暴力枚举+dfs

    又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...

  4. Codeforces Round #325 (Div. 2) B. Laurenty and Shop 有规律的图 暴力枚举

    B. Laurenty and Shoptime limit per test1 secondmemory limit per test256 megabytesinputstandard input ...

  5. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  6. 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)

    /* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...

  7. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

  8. 51nod 1116 K进制下的大数 (暴力枚举)

    题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...

  9. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

随机推荐

  1. C#打印类

    using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;using Sys ...

  2. 【GZAdmin】开源BS demo快速搭建

    下载搭建项目:链接:https://pan.baidu.com/s/1jHZ3Kkm 密码:5k4q 项目源码: GZAdmin_API:https://github.com/GarsonZhang/ ...

  3. 轻谈Normalize.css

    Normalize.css 是 * ? Normalize.css只是一个很小的CSS文件,但它在默认的HTML元素样式上提供了跨浏览器的高度一致性.相比于传统的CSS reset , Normali ...

  4. let与const心智模型

    let 与 const 心智模型: let与const分别是变量与常量的块级声明关键字: 其主要目的是为了约束开发者编写出逻辑更加清晰,阅读性更好的代码: 它们体现了JavaScript的" ...

  5. LeetCode——Counting Bits

    Question Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calcu ...

  6. Java实习一

    简单的二元一次方程求解 import java.lang.Math; import java.util.Scanner; public class Solve{ public static void ...

  7. OpenDayLight "Error executing command: java.lang.NullPointerException"问题解决

    参考: Fedora 21 mostly working but NullPointerException at Karaf shell 在使用ODL的时候,安装功能组件时出现: Error exec ...

  8. bugfree登录后报错PHP Fatal error: Call-time pass-by-reference has been removed in

    详细报错信息[Tue Apr 25 06:49:07.556316 2017] [:error] [pid 21799] [client *.*.*.*:55813] PHP Fatal error: ...

  9. springboot项目属性配置及注意事项

    在idea编辑器建的springboot项目中的resources包下的application.properties这个就是配置文件. 另外配置文件的文件名还可以是application.yml,在r ...

  10. Spark 基于物品的协同过滤算法实现

    J由于 Spark MLlib 中协同过滤算法只提供了基于模型的协同过滤算法,在网上也没有找到有很好的实现,所以尝试自己实现基于物品的协同过滤算法(使用余弦相似度距离) 算法介绍 基于物品的协同过滤算 ...