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);
    		}
    	}
    }
    
  • 相关阅读:
    逆序对
    【模板】树状数组 1
    【模板】树状数组2
    发射站
    质量检测
    【模板】ST表
    winform ComBox绑定数据
    JavaScript CheckBox实现全选和部分选择
    webbrowser内容滚动(javascript内容无缝滚动)
    double? int?
  • 原文地址:https://www.cnblogs.com/ruthank/p/10348861.html
Copyright © 2011-2022 走看看