Circum Triangle - UVa 11186 三角形面积
2015-02-18 14:59
197 查看
Circum Triangle
Input: Standard Input
Output: Standard Output
You will be given N distinct points on the boundary of a circle whose center is at the origin. As the points are on the same circle no three of them are collinear, so any three of them creates a valid triangle. Your job is to find the summation of areas
of these nc3 triangles.
Input
Input file contains at most 16 sets of inputs. The description of each set is given below:
Each set starts with two integers N (0 ≤ N ≤ 500) and R(0<R ≤ 100). Here N is the number of points and R is the radius of the circle. You can assume that the center of the circle is always at the origin. This line is followed by N lines each of which contains
a floating-point number theta (0.0<=theta<360.00) which actually denotes the angle in degree the designated point creates with respect to the origin with x-axis. So for example if theta is 30.00 degree then the Cartesian coordinate of the intended point is
(
![](http://uva.onlinejudge.org/external/111/p11186a.gif)
and
![](http://uva.onlinejudge.org/external/111/p11186b.gif)
. Assume that pi=2cos-1(0).
Input is terminated by a set where the value of N and R is zero. This set should not be processed.
For each line of input produce one line of output. This line contains an integer number which is the total area (rounded to nearest integer) of all possible triangles formed by the given N points. The judge data will be such that small precision errors
题意:就是求n个点可以组成的三角形的面积之和。
思路:运用叉积求三角形面积。
AC代码如下:
Input: Standard Input
Output: Standard Output
You will be given N distinct points on the boundary of a circle whose center is at the origin. As the points are on the same circle no three of them are collinear, so any three of them creates a valid triangle. Your job is to find the summation of areas
of these nc3 triangles.
Input
Input file contains at most 16 sets of inputs. The description of each set is given below:
Each set starts with two integers N (0 ≤ N ≤ 500) and R(0<R ≤ 100). Here N is the number of points and R is the radius of the circle. You can assume that the center of the circle is always at the origin. This line is followed by N lines each of which contains
a floating-point number theta (0.0<=theta<360.00) which actually denotes the angle in degree the designated point creates with respect to the origin with x-axis. So for example if theta is 30.00 degree then the Cartesian coordinate of the intended point is
(
![](http://uva.onlinejudge.org/external/111/p11186a.gif)
and
![](http://uva.onlinejudge.org/external/111/p11186b.gif)
. Assume that pi=2cos-1(0).
Input is terminated by a set where the value of N and R is zero. This set should not be processed.
Output
For each line of input produce one line of output. This line contains an integer number which is the total area (rounded to nearest integer) of all possible triangles formed by the given N points. The judge data will be such that small precision errors
will not cause the output to be different. Consider at least double-precision floating numbers to do your calculations.
Sample Input Output for Sample Input
5 10 10.00 100.00 300.00 310.00 320.00 3 20 10.00 100.00 300.00 0 0 | 286 320 |
思路:运用叉积求三角形面积。
AC代码如下:
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int n; double r,x[510],y[510],p,ans,eps=1e-8; double multiply(int a,int b) { return x[a]*y[b]-y[a]*x[b]; } double area(int a,int b,int c) { return abs(multiply(a,b)+multiply(b,c)+multiply(c,a)); } int main() { int i,j,k; while(~scanf("%d%lf",&n,&r)) { if(n==0 && r==0) break; ans=0; for(i=1;i<=n;i++) { scanf("%lf",&p); p=p/180*M_PI; x[i]=r*cos(p); y[i]=r*sin(p); } for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) for(k=j+1;k<=n;k++) ans+=area(i,j,k); printf("%.0f\n",ans/2); } }
相关文章推荐
- UVA 11186 Circum Triangle (枚举三角形优化)(转)
- UVA 11186 - Circum Triangle(圆上三角形求法)
- 习题10-39 UVA 11186 Circum Triangle圆周上的三角形
- uva 11437 Triangle Fun j求三角形的面积(计算几何)
- C - Circum Triangle UVA - 11186 -枚举+几何
- UVa 11186 Circum Triangle 圆周上的三角形面积之和
- uva 11186 - Circum Triangle
- Circum Triangle UVA - 11186(n^3暴力或n^2容斥推理)
- UVA - 11186-Circum Triangle
- uva 11186 Circum Triangle<叉积>
- UVA 11186 - Circum Triangle(计算几何+容斥)
- UVA 10347 || Medians(中线组成的三角形面积是原三角形的3/4
- ZOJ 2419-- Triangle-凸包+旋转卡壳求最大面积三角形(计算几何)
- UVA 10522 Height to Area(已知三角形三高求面积)
- PKU2079 Triangle 点集最大三角形面积
- 写一个程序,定义抽象基类Shape,由它派生出3个派生类,Circle(圆形)、Rectangle(矩形)、Triangle(三角形)。用如下的main()函数,求出定义的几个几何体的面积和。
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
- JAVA之1.封装一类三角形对象Triangle,该类对象具有三条边的属性,具有初始化三角形的功能、修改边长的功能、判断三条边能否构成三角形的功能、求周长的功能、求面积的功能。
- 飛飛(四十七)定义抽象基类Shape,由它派生出3个派生类,Circle(圆形)、Rectangle(矩形)、Triangle(三角形)。用如下的main()函数,求出定义的几个几何体的面积和。
- poj2954-Triangle 求三角形的面积(已知三角形三点求面积)