hrbust 2354 An Easy Geometry Problem

来源:互联网 发布:json remove key 编辑:程序博客网 时间:2024/05/02 00:35

An Easy Geometry ProblemTime Limit: 1000 MSMemory Limit: 262144 KTotal Submit: 52(25 users)Total Accepted: 19(16 users)Rating: Special Judge: NoDescription

Lily is interested in hyperspace recently, and she is trying to solve an easy problem now. Given an n-dimensional hyperspace, assuming each dimension is a1, a2, a3, ..., an. And for each i (1 ≤ ≤ n), j (i < j ≤ n), there is a plane ai=aj  These planes have divided the hyperspace into different regions. For example, in 3D hyperspace, we have three planes: x=y, y=z and x=z.

Now given q queries, for each query, there is a point (x1, x2, x3, ..., xn). Lily wants to know the maximum radius r of an n-dimensional ball she can put in point (x1, x2, x3, ..., xn), which means the center of the ball is in point (x1, x2, x3, ..., xn) and the ball’s surface cannot cross but can touch any planes mentioned above.

The equation of an n-dimensional ball with center (x1, x2, x3, ..., xn) is . And the distance between two points (x1, x2, x3, ..., xn) and (x1', x2', x3', ..., xn') in an n-dimensional hyperspace is:.

Input

First line contains an integer T (1 ≤ ≤ 5), represents there are T test cases.

For each test case: First line contains two integers n (3 ≤ ≤ 50000) and q (1 ≤ ≤ 8), where n is the dimension of the hyperspace, and q is the number of queries. Following q lines, each line contains n integers x1, x2, x3, ..., xn (-109 ≤ xi ≤ 109), represents the coordinate of the balls center.

Output

For each test case, output one line containing "Case #X:"(without quotes), where X is the case number starting from 1, and output q lines containing the maximum possible radius of the ball in each query in input order, rounded to four decimal places.

Sample Input

1

3 2

0 0 0

11 22 33

Sample Output

Case #1:

0.0000

7.7782


Source“科林明伦杯”哈尔滨理工大学第七届程序设计团队赛
读题两小时实现5分钟。


最大圆半径。(满足  These planes have divided the hyperspace into different regions. For example, in 3D hyperspace, we have three planes: x=y, y=z and x=z


转化成2维直接找到规律。

#include<stdio.h>#include<math.h>#include<algorithm>using namespace std;#define N 100005int T;double r[N];int main(){    scanf("%d",&T);    int icase=0;    while(T--){        int n,m;        printf("Case #%d:\n",++icase);        scanf("%d%d",&n,&m);        while(m--){            for(int i=0;i<n;i++){                scanf("%lf",&r[i]);            }            sort(r,r+n);            double res = 1e15;            for(int i=1;i<n;i++){                res = min(res,r[i]-r[i-1]);            }            printf("%.4f\n",res/sqrt(2.0));        }    }}



原创粉丝点击