zoukankan      html  css  js  c++  java
  • UVA

    圆上有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);
    		}
    	}
    }
    
  • 相关阅读:
    bat入门--第一个bat文件
    Egret的Shape
    Less Time, More profit 最大权闭合子图(最大流最小割)
    Mayor's posters POJ
    Stars POJ
    Snacks
    有趣的数列 卡特兰数
    Devu and Flowers lucas定理+容斥原理
    整数分解为2的幂 数学
    易碎的鸟蛋 概率DP
  • 原文地址:https://www.cnblogs.com/ruthank/p/10348861.html
Copyright © 2011-2022 走看看