圆上有n个点,位置不确定。问这些点两两连接成的线段,最多可以把圆划分成多少块平面?
欧拉公式:V-E+F = 2,V是点数,E是边数,F是面数。
答案是F=C(n,4)+C(n,2)+1,看的别人推的。。我实在推不出来。
写这篇博客的原因是第一次用Java的BigInteger。
import java.math.BigInteger; import java.util.*; public class Main{ static Scanner sc = new Scanner(System.in); public static void main(String args[]){ int t = sc.nextInt(); for (int ca = 1; ca <= t; ca++) { String s = sc.next(); BigInteger n = new BigInteger(s); BigInteger ans = BigInteger.valueOf(1); BigInteger tmp = new BigInteger(s); for (int i = 1; i <= 3; i++) { BigInteger k = BigInteger.valueOf(i); tmp = tmp.multiply(n.subtract(k)); } for (int i = 1; i <= 4; i++) { BigInteger k = BigInteger.valueOf(i); tmp = tmp.divide(k); } ans = ans.add(tmp); tmp = new BigInteger(s); tmp = tmp.multiply(n.subtract(BigInteger.valueOf(1))); tmp = tmp.divide(BigInteger.valueOf(2)); ans = ans.add(tmp); System.out.println(ans); } } }
原文地址:https://www.cnblogs.com/ruthank/p/10348861.html
时间: 2024-10-29 18:08:44