UVA 10213 - How Many Pieces of Land ? (平面图欧拉公式)

博客给出题目链接,题意是求椭圆上N个点两两连接最多将椭圆划分成多少部分。解题思路是运用平面图欧拉公式V−E+F = 2,所求结果为ans = E−V + 1,之后需计算顶点V和边E的数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接 https://cn.vjudge.net/problem/UVA-10213

【题意】
一个椭圆上有N个点,把他们两两连接,问最多能将椭圆划分成多少个部分

【思路】
平面图的欧拉公式, VE+F=2 V − E + F = 2 ,其中V表示顶点个数,E表示边的个数,F表示面的块数
减去最外面的无限大的面,所求 ans=EV+1 a n s = E − V + 1
然后就是计算V和E了,假设 n4 n ≥ 4 ,从圆周上的一个点出发枚举一条对角线,左边有 i i 个点,右边有n2i个点,将左右两边的点两两相连,就在这条对角线上得到 i(n2i) i ( n − 2 − i ) 个点,每个点会被重复算4次,再加上圆周上的 n n 个点所以

V=n+n4i=1n3i(ni2)

然后计算E,一条对角线有 i(n2i) i ( n − 2 − i ) 个点,这条对角线上就会有 i(n2i)+1 i ( n − 2 − i ) + 1 条边,每条边会被重复计算两次,再加上原来圆弧上的 n n 条边和相邻结点相邻的n条边,所以

E=2n+n2i=1n3(i(ni2)+1) E = 2 n + n 2 ∑ i = 1 n − 3 ( i ( n − i − 2 ) + 1 )

再借助于下面两个公式去化简
i=1ni=n(n+1)2 ∑ i = 1 n i = n ( n + 1 ) 2
i=1ni2=n(n+1)(2n+1)6 ∑ i = 1 n i 2 = n ( n + 1 ) ( 2 n + 1 ) 6
得到的最终答案为
ans=124n(n36n2+23n18)+1 a n s = 1 24 n ( n 3 − 6 n 2 + 23 n − 18 ) + 1

import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int T=input.nextInt();
        for(int kase=1;kase<=T;++kase) {
            BigInteger n=input.nextBigInteger();
            BigInteger ans=n.pow(3);
            ans=ans.subtract(n.pow(2).multiply(BigInteger.valueOf(6)));
            ans=ans.add(n.multiply(BigInteger.valueOf(23)));
            ans=ans.subtract(BigInteger.valueOf(18));
            ans=ans.multiply(n);
            ans=ans.divide(BigInteger.valueOf(24));
            ans=ans.add(BigInteger.ONE);
            System.out.println(ans);
        }
        input.close();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值