组队训练赛第一场5215 Problem D Fence Building

解决在一个圆内通过连接N个点划分最多区域的问题,采用最优策略确保任意三条线不交于一点,利用组合数学推导出最大区域数。

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

题目描述

Farmer John owns a farm. He first builds a circle fence. Then, he will choose n points and build some straight fences connecting them. Next, he will feed a cow in each region so that cows cannot play with each other without breaking the fences. In order to feed more cows, he also wants to have as many regions as possible. However, he is busy building fences now, so he needs your help to determine what is the maximum number of cows he can feed if he chooses these n points properly.

 

输入

The first line contains an integer 1 ≤ T ≤ 100000, the number of test cases. For each test case, there is one line that contains an integer n. It is guaranteed that 1 ≤ T ≤ 105 and 1 ≤ n ≤ 1018 .

 

输出

For each test case, you should output a line ”Case #i: ans” where i is the test case number, starting from 1 and ans is the remainder of the maximum number of cows farmer John can feed when divided by 109 + 7.
 

 

样例输入

3
1
3
5
​

 

样例输出

Case #1: 1
Case #2: 4
Case #3: 16

题意:在一个圆中有N个点,链接N个点,尽可能划分最多的区域。

题解:最优策略总是在选定 n 个点后,两两连线,且满足任意三条线不交于一点。
尝试统计总的结点个数 A(n)与独立线段(包括圆弧上的 n 段小弧)的总个数 B(n),然后
利用欧拉公式就可以得到答案 Ans(n)=B(n)-A(n)+1。
任意四个点,会形成一个交点,并贡献额外的 2 条独立线段。所以 A(n)=n+C(n,4),而
B(n)=n+2C(n,4)+C(n,2),所以最后答案为 C(n,2)+C(n,4)+1。

1——1

2——2

3——4

4——8

5——16

6——31

7——57

数列1 ,2,4,8,16,31,57~

ll qpow(ll x,ll y){
    ll ans=1;
    while(y){
        if(y%2) ans=ans*x%mod;
        x=x*x%mod;
        y/=2;
    }
    return ans;
}
ll inv(ll x){
    return qpow(x,mod-2);
}


//inv(24)=1/24
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+7;
const ll mod=1e9+7;
ll qpow(ll x,ll y){
    ll ans=1;
    while(y){
        if(y%2) ans=ans*x%mod;
        x=x*x%mod;
        y/=2;
    }
    return ans;
}
ll inv(ll x){
    return qpow(x,mod-2);
}

int main()
{
    int t;ll n;
    scanf("%d",&t);
    ll x,y,x1,y1;
    int flag=1;
    while(t--){
        ll ans=0;
        scanf("%lld",&n);
        ans=((n%mod*((n-1)%mod)%mod)*((n-2)%mod)%mod*((n-3)%mod)%mod)*(inv(24)%mod)%mod;
        ans=(ans+(n%mod*((n-1)%mod)%mod)*(inv(2)%mod)%mod+1)%mod;
        printf("Case #%d: %lld\n",flag++,(ans+mod)%mod);

    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值