您的位置:首页 > 其它

1007(数组,时间超限)

2017-03-19 11:16 127 查看
Problem Description

Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded.

In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a
configuration of the field, you are supposed to find the radius of such a ring.

Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered
to be 0.

Input

The input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates of a toy. The input is terminated
by N = 0.

Output

For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places.

Sample Input

2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0


Sample Output

0.71
0.00
0.75


#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
int N;
float coordinates[100000][3];
while(cin>>N&&N!=0&&N>=2&&N<=100000)
{

for(int i=0;i<N;i++)
cin>>coordinates[i][0]>>coordinates[i][1];
float radius,minRadius;
minRadius=(sqrt((coordinates[0][0]-coordinates[1][0])*(coordinates[0][0]-coordinates[1][0])+
(coordinates[0][1]-coordinates[1][1])*(coordinates[0][1]-coordinates[1][1])))/2;
for(int i=1;i<N-1;i++)
for(int j=i+1;j<N;j++)
{
if(coordinates[i][0]==coordinates[j][0]&&coordinates[i][1]==coordinates[j][1])
{
cout<<0.00<<endl;
break;
}
radius=(sqrt((coordinates[i][0]-coordinates[j][0])*(coordinates[i][0]-coordinates[j][0])+
(coordinates[i][1]-coordinates[j][1])*(coordinates[i][1]-coordinates[j][1])))/2;
if(minRadius>radius)
minRadius=radius;
}
cout<<fixed<<setprecision(2)<<minRadius<<endl;
}
return 0;
}


刚开始用数组的时候就已经感觉时间会超限了,没想到还真的超限的,刚开始用的数组用的double型,编译没有错误,一运行软件就提示程序停止工作,最后找了很久才发现时double数组长度的问题,这应该算是个低级问题了吧,果然还是菜鸟啊。既然数组做法时间超限,而且感觉也没法修改了吧,看来又得膜拜大神了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐