UVA - 10213 How Many Pieces of Land?(欧拉公式 + 高精度)

Posted ruthank

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA - 10213 How Many Pieces of Land?(欧拉公式 + 高精度)相关的知识,希望对你有一定的参考价值。

圆上有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?(欧拉公式 + 高精度)的主要内容,如果未能解决你的问题,请参考以下文章

UVA - 10213 How Many Pieces of Land?(欧拉公式 + 高精度)

UVa 10213 How Many Pieces of Land ? (计算几何+大数)

UVA - 10061 How many zero&#39;s and how many digits ?

How Many O's? UVA - 11038

hdu 1316 How Many Fibs?

P - How many