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. centos ssh免密码秘钥登录

    假设从A主机ssh登录B主机,用秘钥代替密码,步骤如下: 1.在A主机上执行:ssh-keygen -t  rsa 一切默认,不用输入密码,生成两个文件: /root/.ssh/id_rsa /roo ...

  2. 适配移动端的在图片上生成水波纹demo

      <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&q ...

  3. 对Spring Ioc 以及DI的精彩理解

    转:http://blog.csdn.net/cyjs1988/article/details/50352916 学习过spring框架的人一定都会听过Spring的IoC(控制反转) .DI(依赖注 ...

  4. 软件测试技术作业3---PrintPrimes()

    一.代码部分: private static void printPrimes (int n) { int curPrime; // Value currently considered for pr ...

  5. logstash运输器以及kibana的更多操作

    为了达到不会因为ELK中的某一项组件因为故障而导致整个ELK工作出问题,于是 将logstash收集到的数据存入到消息队列中如redis,rabbitMQ,activeMQ或者kafka,这里以red ...

  6. awk十三问-【AWK学习之旅】

    ---===AWK学习之旅===--- 十三个常用命令行处理   [root@monitor awkdir]# cat emp.txt Beth 4.00 0 Dan 3.75 0 Kathy 4.0 ...

  7. 通过Excel生成批量SQL语句

    项目中有时会遇到这样的要求:用户给发过来一些数据,要我们直接给存放到数据库里面,有的是Insert,有的是Update等等,少量的数据我们可以采取最原始的办法,也就是在SQL里面用Insert int ...

  8. cygwin下烧写文件到sd卡中

    在cygwin下将firmware_sdcard.bin写入到sd卡中(cygwin需要以管理员身份启动) 1查看sd分区情况 cat /proc/partitions  (为了找到sd卡的标记) 2 ...

  9. mybatis动态插入数据(使用trim标签)

    知识点: 当向一张表里插入数据,传入的参数不固定时,使用到mybatis的动态插入(trim标签) 参考博客:https://blog.csdn.net/h12kjgj/article/details ...

  10. HTTP协议中的COOKIE机制简单理解

    1.为什么会有COOKIE这种机制 首先一种场景, 在一个网站上面, 我发起一次请求,那服务器怎么知道我是谁?是谁发起的这次请求呢, HTTP协议是无状态的协议, 浏览器的每一次请求,服务器都当做一次 ...