joj 1173
2011-04-06 21:27
288 查看
1173: Circle More Alike
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
3s | 8192K | 661 | 258 | Standard |
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 isan 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 formuladescribed 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; }
相关文章推荐
- JOJ 1026 The staircases
- JOJ 2171 2488 1868 2237
- JOJ 1058 T9 解题报告
- JOJ 1198: Risk
- JOJ 2412 Divide the finger
- joj2697
- joj 2699: 16 and 18 博弈 最后一个取石子者输
- joj 2437: The grabber 等周定理变形 一直两端点和周长,求最大面积
- joj 1966 Super Market III 带期限的作业排序
- joj 1509Hamiltonian Cycle (dfs求H回路)
- joj 2426
- joj2471
- joj 2724: Hua Rong Dao 最小割
- joj1006
- joj 1317
- joj 2717
- JOJ2573:Product of two primes
- joj 1928
- JOJ 1006解题
- 大数相加,高精度阶乘,大整数进制转换,大整数判断被小整数整除(JOJ--1029)