您的位置:首页 > 编程语言 > PHP开发

joj 1173

2011-04-06 21:27 288 查看

1173: Circle More Alike

ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE

3s8192K661258Standard
1st Jilin University ACM International Collegiate Programming
Contest

In this problem, you are to write a program to calculate the roundness of a
polygon. The roundness of a polygon is defined the quotient of its area and the
square of its circumference. More specifically:



In order to calcuate the area of a polygon, you need another
formula:



where (xi, yi) are the coordinates of the vertex i(in direction of
clockwise) of the polygon and n is the number of vertices.

Input Specification

The input consists of M polygons. The first line of the input is
an integer M. Then follow M polygons, each of which is described below:
n
x0 y0
x1 y1
...
xn-1 yn-1
where n(3<=n<=100) is the number of vertices of the polygon
and (xi, yi) are integers. The coordinates of the vertices of each polygon are
given in the sequence of clockwise.

Output Specification

For each polygon, you should print its roundness by the formula
described above. Each polygon occupies a single line in the output. The
roundness should be accurated to 0.001.

Sample Input

2
4
0 0
0 1
1 1
1 0
3
0 0
1 1
2 0

Sample Output

0.063
0.043


 
This problem is used for contest: 110 
Submit / Problem List / Status / Discuss

 

 

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
struct POINT
{
double x;
double y;
POINT(double a=0, double b=0)
{
x=a;    //constructor
y=b;
}
};
double dist(POINT p1,POINT p2)                // 返回两点之间欧氏距离
{
return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );
}
double area_of_polygon(int vcount,POINT polygon[])
{
int i;
double s;
if (vcount<3) return 0;
s=polygon[0].y*(polygon[vcount-1].x-polygon[1].x);
for (i=1; i<vcount; i++)
s+=polygon[i].y*(polygon[(i-1)].x-polygon[(i+1)%vcount].x);
return s/2;
}
POINT p[101];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)  cin>>p[i].x>>p[i].y;
double s=area_of_polygon(n,p);
if(s<0)  s=-s;
double t=0;
for(int i=1; i<n; i++)  t+=dist(p[i],p[i-1]);
t+=dist(p[0],p[n-1]);
s=s/(t*t);
printf("%0.3lf/n",s);
}
return 0;
}
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  each input integer output list