牛客网暑期ACM多校训练营(第八场)G-Counting regions

链接:https://www.nowcoder.com/acm/contest/146/G
来源:牛客网
 

题目描述

Niuniu likes mathematics. He also likes drawing pictures. One day, he was trying to draw a regular polygon with n vertices. He connected every pair of the vertices by a straight line as well. He counted the number of regions inside the polygon after he completed his picture. He was wondering how to calculate the number of regions without the picture. Can you calculate the number of regions modulo 1000000007? It is guaranteed that n is odd.

输入描述:

The only line contains one odd number n(3 ≤ n ≤ 1000000000), which is the number of vertices.

输出描述:

Print a single line with one number, which is the answer modulo 1000000007.

输入

3

输出

1

输入

5

输出

11

备注:

The following picture shows the picture which is drawn by Niuniu when n=5. Note that no three diagonals share a point when n is odd.

题意:给你一个正n边形,将n个顶点两两连边,问内部有多少个区域。

思路:比赛的时候,理学院的队友,看了看,说咱们做过,然后噼里啪啦就敲完了,之前我们做过圆内接正多边形分割区域的数量,貌似就是这道题:UVa 10213 How Many Pieces of Land ?,我们在原题基础上减了一圈边就过了,即c_{n}^{2}+c_{n}^{4}+1-n

赛后整理:两道题都是利用欧拉公式:在平面图中,V-E+F=2,其中V是顶点数,E是边数,F是面数。

所以我们只要推出点和边的数量就好了,然后本题中顶点数是奇数,那么不会出现多条线交在一起,计算起来更为简单,

推导过程大家还是看这篇文章吧,我就不献丑了。插个眼回头补。

补:

        当时说实话一知半解,然后紧接着继续打多校比赛,今天有空重新重新思考了这个题,我们依然依靠的是欧拉公式,V是顶点数,E是边数,F是区域块数,首先圆上四个顶点可以确定一个内部交点,假设有外接圆考虑的情况下,V=n+C_{n}^{4},一个交点可以吧一个线段分成两段,每两个点可以连一条线,E=C_{n}^{2}+C_{n}^{4}*2,所以F=E-V+2就可以求出来了...

 2补:

       被推荐了一个很棒的视频,【官方中配】分圆问题,诡异的数列规律:解答篇

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>

using namespace std;

#define inf 0x3f3f3f3f

const int maxn=1e9+7;

const int mod=1e9+7;

long long quick_pow(long long a, long long n)
{
    long long ans=1;
    while(n)
    {
        if(n&1)ans=(ans*a)%mod;
        n/=2;
        a=(a*a)%mod;
    }
    return ans;
}
int main()
{
    long long n;
    while(~scanf("%lld",&n))
    {
        long long ans=(((n*(n-1)%mod)*quick_pow(2,mod-2)+1-n)%mod+mod)%mod;
        if(n>=5) ans+=n*(n-1)%mod*(n-2)%mod*(n-3)%mod*quick_pow(24,mod-2)%mod;
        printf("%lld\n",ans%mod);
    }
    return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值