【 Circum Triangle】uva 解题 3/4

题目连结

解题

根据公式=>把角度换成点的位置用外积(叉积)得三角行面积记得用long最后用还有绝对值

java code

import java.util.*;public class Circum_Triangle {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int N = sc.nextInt();        double r = sc.nextDouble();        while (N != 0 || r != 0) {            double ans = 0;            double[][] point = new double[N][2];// using x and y to express point(in x-axis and y-axis)            for (int i = 0; i < N; i++) {                double x = sc.nextDouble();                point[i][0] = r * Math.cos(x / 180 * Math.PI);                point[i][1] = r * Math.sin(x / 180 * Math.PI);            }            for (int i = 0; i < N; i++) {                for (int j = i + 1; j < N; j++) {                    for (int k = j + 1; k < N; k++) { // Calculate the cross product for three points and determine the                                                      // area of the resulting triangle                        double area = Math.abs((point[i][0] - point[j][0]) * (point[i][1] - point[k][1])                                - (point[i][1] - point[j][1]) * (point[i][0] - point[k][0])) / 2.0;                        ans += area;                    }                }            }                        System.out.println((long) Math.round(ans));            N = sc.nextInt();            r = sc.nextDouble();        }        sc.close();    }}

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章