题目连结
解题
根据公式=>把角度换成点的位置用外积(叉积)得三角行面积记得用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(); }}