UVA 10213 How Many Pieces of Land? 欧拉定理
来源:互联网 发布:量化对冲交易软件 编辑:程序博客网 时间:2024/05/16 18:52
欧拉定理 V-E+F=C+1
How Many Pieces of Land?
Input: Standard Input
Output: Standard Output
Time Limit: 3 seconds
You are given an elliptical shaped land and you are asked to choose n arbitrary points on its boundary. Then you connect all these points with one another with straight lines (that’s n*(n-1)/2 connections for n points). What is the maximum number of pieces of land you will get by choosing the points on the boundary carefully?
Fig: When the value of n is 6.
Input
The first line of the input file contains one integer S (0 < S < 3500), which indicates how many sets of input are there. The next S lines contain S sets of input. Each input contains one integer N (0<=N<2^31).
Output
For each set of input you should output in a single line the maximum number pieces of land possible to get for the value of N.
Sample Input:
41
2
3
4
Sample Output:
12
4
8
Shahriar Manzoor
/** * Created by ckboss on 15-2-1. */import java.math.BigInteger;import java.util.*;public class Main { BigInteger pfh(BigInteger n){ return n.multiply((n.add(BigInteger.ONE))).multiply((n.multiply(BigInteger.valueOf(2))).add(BigInteger.ONE)).divide(BigInteger.valueOf(6)); } BigInteger getV(BigInteger n){ BigInteger A = n.subtract(BigInteger.valueOf(2)); BigInteger B = n.subtract(BigInteger.valueOf(3)); BigInteger temp = A.multiply(B).divide(BigInteger.valueOf(2)).multiply(A).subtract(pfh(B)); temp = temp.multiply(n).divide(BigInteger.valueOf(4)); return temp.add(n); } BigInteger getE(BigInteger n){ BigInteger A = n.subtract(BigInteger.valueOf(2)); BigInteger B = n.subtract(BigInteger.valueOf(3)); BigInteger temp = A.multiply(B).divide(BigInteger.valueOf(2)).multiply(A).subtract(pfh(B)).add(n).subtract(BigInteger.ONE); temp = temp.multiply(n).divide(BigInteger.valueOf(2)); return temp.add(n); } Main(){ Scanner in = new Scanner(System.in); int T_T = in.nextInt(); while(T_T-->0) { BigInteger n = in.nextBigInteger(); BigInteger V = getV(n); BigInteger E = getE(n); BigInteger F = BigInteger.ONE.subtract(V).add(E); System.out.println(F); } } public static void main(String[] args){ new Main(); }}
- UVA 10213 How Many Pieces of Land? 欧拉定理
- UVa 10213 How Many Pieces of Land (欧拉定理)
- uva 10213 how many pieces of land
- UVA-10213 How many pieces of land
- UVa 10213 How Many Pieces of Land?
- UVa 10213 How Many Pieces of Land ?
- UVa 10213 How Many Pieces of Land ? (数学&欧拉公式&高精度)
- UVa Problem Solution: 10213 - How Many Pieces of Land?
- UVA 10213(p336)----How Many Pieces of Land
- uva 10213 How Many Pieces of Land 分割圆 高精度
- How many pieces of land?
- (计算几何8.1.3.1)UVA 10213 How Many Pieces of Land?(使用欧拉公式的应用顶点数+面数-棱数 = 2)
- UVa Problem 10213 How Many Pieces of Land? (土地分割)
- 【UVA】10213 - How Many Pieces of Land ?(大树模板X2)
- uva_10213 - How Many Pieces of Land ?
- UVaOj How many pieces of land?
- UVa10213 - How Many Pieces of Land ?
- 110602 How Many Pieces of Land
- 跟着实例学习java多线程6-如何正确发布线程安全的对象
- 不使用比较运算就可以求出两个数的最大值与最小值
- 小记:2/2
- SATA I, SATA II, SATA III区别
- ibatis-dao框架中相关实例域存在原因总结
- UVA 10213 How Many Pieces of Land? 欧拉定理
- 设置Git不需要每次push都输入用户名和密码
- 各种分散的点
- 人总是熬出头的
- iOS屏幕适配
- 早会的原则
- Python map/reduce vs 列表推导式[list comprehension]
- 自怜之说
- 预编译头文件