How Many Pieces of Land ? UVA - 10213 (计算几何公式)

How Many Pieces of Land ?

UVA - 10213

Lemma

Lemma

If we already have n points on the circle and add one more point, we draw n lines from the new point to previously existing points. Two cases are possible. In the first case (a), the new line passes through a point where two or more old lines (between previously existing points) cross. In the second case (b), the new line crosses each of the old lines in a different point. It will be useful to know the following fact.

Lemma. We can choose the new point A so that case b occurs for each of the new lines.

Proof. Notice that, for the case a, three points must be on one line: the new point A, the old point O to which we draw the line, and the point I where two of the old lines intersect. Notice that there are n old points O, and hence finitely many points I where two of the old lines intersect. For each O and I, the line OI crosses the circle in one point other than O. Since the circle has infinitely many points, it has a point A which will be on none of the lines OI. Then, for this point A and all of the old points O, case b will be true.

This lemma means that, if there are k lines crossing AO, then each of them crosses AO at a different point and k+1 new areas are created by the line AO.

Solution

Inductive method

The lemma establishes an important property for solving the problem. By employing an inductive proof, one can arrive at a formula for f(n) in terms of f(n − 1).

Proof

In the figure you can see the dark lines connecting points 1 through 4 dividing the circle into 8 total regions (i.e., f(4) = 8). This figure illustrates the inductive step from n = 4 to n = 5 with the dashed lines. When the fifth point is added (i.e., when computing f(5) using f(4)), this results in four new lines (the dashed lines in the diagram) being added, numbered 1 through 4, one for each point that they connect to. The number of new regions introduced by the fifth point can therefore be determined by considering the number of regions added by each of the 4 lines. Set i to count the lines we are adding. Each new line can cross a number of existing lines, depending on which point it is to (the value of i). The new lines will never cross each other, except at the new point.

The number of lines that each new line intersects can be determined by considering the number of points on the "left" of the line and the number of points on the "right" of the line. Since all existing points already have lines between them, the number of points on the left multiplied by the number of points on the right is the number of lines that will be crossing the new line. For the line to point i, there are

ni − 1

points on the left and

i − 1 points

on the right, so a total of

( ni − 1) ( i − 1)

lines must be crossed.

In this example, the lines to i = 1 and i = 4 each cross zero lines, while the lines to i = 2 and i = 3 each cross two lines (there are two points on one side and one on the other).

So the recurrence can be expressed as

f ( n ) = f ( n − 1 ) + ∑ i = 1 n − 1 ( 1 + ( n − i − 1 ) ( i − 1 ) ) {\displaystyle f(n)=f(n-1)+\sum _{i=1}^{n-1}\left(1+\left(n-i-1\right)\left(i-1\right)\right)} f(n)=f(n-1)+\sum^{n-1}_{i=1}\left(1+\left(n-i-1\right)\left(i-1\right)\right)

which can be easily reduced to

f ( n ) = f ( n − 1 ) + ∑ i = 1 n − 1 ( 2 − n + n i − i 2 ) {\displaystyle f(n)=f(n-1)+\sum _{i=1}^{n-1}\left(2-n+ni-i^{2}\right)} f(n)=f(n-1)+\sum^{n-1}_{i=1}\left(2-n+ni-i^2\right)

using the sums of the first ( n − 1 ) {\displaystyle (n-1)} (n-1) natural numbers and the first ( n − 1 ) {\displaystyle (n-1)} (n-1) squares, this combines to

f ( n ) = f ( n − 1 ) + 1 6 n 3 − n 2 + 17 6 n − 2 {\displaystyle f(n)=f(n-1)+{\frac {1}{6}}n^{3}-n^{2}+{\frac {17}{6}}n-2} f(n)=f(n-1)+\frac{1}{6}n^3-n^2+\frac{17}{6}n-2

Finally

f ( n ) = ∑ k = 1 n ( 1 6 k 3 − k 2 + 17 6 k − 2 ) + 1 {\displaystyle f(n)=\sum _{k=1}^{n}\left({\frac {1}{6}}k^{3}-k^{2}+{\frac {17}{6}}k-2\right)+1} f(n)=\sum^{n}_{k=1}\left(\frac{1}{6}k^3-k^2+\frac{17}{6}k-2\right)+1 with f ( 0 ) = 1 {\displaystyle f(0)=1} f(0)=1

which yields

f ( n ) = n 24 ( n 3 − 6 n 2 + 23 n − 18 ) + 1 {\displaystyle f(n)={\frac {n}{24}}(n^{3}-6n^{2}+23n-18)+1}

f(n)=\frac{n}{24}(n^3-6n^2+23n-18)+1
code:

import java.math.*;
import java.util.Scanner;
public class Main{
    public static void main(String[]args) {
    	Scanner scanner = new Scanner(System.in);
    	int t = scanner.nextInt();
    	BigInteger n;
    	while(t-- > 0) {
    		n = scanner.nextBigInteger();
    		BigInteger ans = BigInteger.ZERO;
    		BigInteger a = n.pow(4);
    		BigInteger b = n.pow(3).multiply(BigInteger.valueOf(6));
    		BigInteger c = n.pow(2).multiply(BigInteger.valueOf(23));
    		BigInteger d = n.multiply(BigInteger.valueOf(18));
    		ans = ans.add(a).subtract(b).add(c).subtract(d);
    		ans = ans.divide(BigInteger.valueOf(24)).add(BigInteger.ONE);
    		System.out.println(ans);
    	}
    }
	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值