UVA - 10213 How Many Pieces of Land?(歐拉公式 + 高精度)
阿新 • • 發佈:2019-02-02
平面 divide multiply ger brush trac tin val value
圓上有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); } } }
UVA - 10213 How Many Pieces of Land?(歐拉公式 + 高精度)