(第八场)G Counting regions 【欧拉公式】
题目链接:https://www.nowcoder.com/acm/contest/146/G
G、Counting regions
| 时间限制:1 秒 | 内存限制:128M
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.
备注: The following picture shows the picture which is drawn by Niuniu when n=5. Note that no more than three diagonals share a point when n is odd.
示例 1
输入
3
输出
1
示例2
输入
5
输出
11
题意概括:
给你一个正n边形,将n个顶点两两连边,问内部有多少个区域。n是奇数。
官方题解:
欧拉公式:F=E-V+2
内部交点个数:C(n,4)
一条线段会被一个交点分成两段,所以x条直线的交点会多分出来x条线段,利用V 可以算出E。
解题思路:
根据欧拉公式:F:面数;E:边数;V:顶点数
当V >= 4时,多边形满足 V-E+F = 2;
因为N是奇数,所以任意选取四个顶点连接,两条对角线相交于一点,交点两两不重合,所以内部交点个数为 C(n, 4);
而内部边数 = 对角线数 + 内部交点数*2 (即 C(n, 2) + C(n, 4)*2);
最后边数,结点数已知,可求面数。
注意细节:
求组合时数据偏大有取模操作,除法运算要通过逆元转换为乘法,这里求逆元的方法是用费马小定理。
AC code:
///欧拉公式+费马小定理求逆元
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstring>
#define INF 0x3f3f3f3f
#define ll long long int
#define mod 1000000007
using namespace std; ll N, V, E;
ll quick_pow(ll a, ll b)
{
ll ans = ;
while(b)
{
if(b&) ans = ans*a%mod;
a = a*a%mod;
b>>=;
}
return ans;
}
int main()
{
scanf("%lld", &N);
V = N*(N-)%mod*(N-)%mod*(N-)%mod*quick_pow(,mod-)%mod; ///内部交点
E = (V* + (N*(N-)/)%mod)%mod; ///边数
V = (V + N)%mod; ///顶点数
ll F = ((E-V+)%mod+mod)%mod; ///面数
printf("%lld\n", F);
return ;
}
(第八场)G Counting regions 【欧拉公式】的更多相关文章
- 牛客多校训练第八场G.Gemstones(栈模拟)
题目传送门 题意: 输入一段字符串,字符串中连续的三个相同的字符可以消去,消去后剩下的左右两段字符串拼接,求最多可消去次数. 输入:ATCCCTTG 输出:2 ATCCCTTG(消去CCC)——& ...
- 牛客多校第八场 G Gemstones 栈/贪心
题意: 对于一个序列,把可以把连着三个相同的字母拿走,问最多拿走多少组. 题解: 直接模拟栈,三个栈顶元素相同则答案+1,并弹出栈 #include<bits/stdc++.h> usin ...
- [HDU6304][数学] Chiaki Sequence Revisited-杭电多校2018第一场G
[HDU6304][数学] Chiaki Sequence Revisited -杭电多校2018第一场G 题目描述 现在抛给你一个数列\(A\) \[ a_n=\begin{cases}1 & ...
- 牛客多校第三场 G Removing Stones(分治+线段树)
牛客多校第三场 G Removing Stones(分治+线段树) 题意: 给你n个数,问你有多少个长度不小于2的连续子序列,使得其中最大元素不大于所有元素和的一半 题解: 分治+线段树 线段树维护最 ...
- 2019牛客多校第八场 F题 Flowers 计算几何+线段树
2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...
- 2020牛客多校第八场K题
__int128(例题:2020牛客多校第八场K题) 题意: 有n道菜,第i道菜的利润为\(a_i\),且有\(b_i\)盘.你要按照下列要求给顾客上菜. 1.每位顾客至少有一道菜 2.给顾客上菜时, ...
- ACM-ICPC 2017 Asia Urumqi(第八场)
A. Coins Alice and Bob are playing a simple game. They line up a row of nnn identical coins, all wit ...
- 牛客多校第四场 G Maximum Mode
链接:https://www.nowcoder.com/acm/contest/142/G来源:牛客网 The mode of an integer sequence is the value tha ...
- 牛客多校第二场 G transform
链接:https://www.nowcoder.com/acm/contest/140/G White Cloud placed n containers in sequence on a axes. ...
随机推荐
- JetBrains PyCharm(Community版本)的下载、安装和初步使用
不多说,直接上干货! 首先谈及这款软件,博主我用的理由:搞机器学习和深度学习! 想学习Python的同学们,在这里隆重介绍一款 Python 的开发工具 pyCharm IDE.这是我最喜欢的 Pyt ...
- Android模拟器访问本机服务器
Android模拟器访问本机服务器,用127.0.0.1访问不到,因为127.0.0.1已经被映射到模拟器了. 可以用以下两种方式访问 1. 用 10.0.2.2 2. 直接用 本机的IP地址,如:1 ...
- artDialog组件应用学习(五)
一.artDialog事件应用 对话框编写代码 function DialogEvent() { seajs.use(['jquery', '/Scripts/arale/artDialog/src/ ...
- 05.while循环的练习
练习1: namespace _05.while循环练习01 { class Program { static void Main(string[] args) { //打印100次"努力学 ...
- java中如何遍历实体类的属性和数据类型以及属性值
package com.walkerjava.test; import java.lang.reflect.Field; import java.lang.reflect.InvocationTa ...
- Django分页解析
分页 django中实现管理数据分页的类位于 django.core.paginator.py中 Paginator类 对列表数据进行分页处理 对象 Paginator(Post.objects.al ...
- laravel vue.js的使用
安装cors 地址:https://github.com/barryvdh/laravel-cors 在Kernel文件中加上 protected $middleware = [ \Barryv ...
- ECMAScript 6简介
一.起步 1.扎实的HTML/CSS/Javascript基本功,这是前置条件. 2.不要用任何的构建项目工具,只用最简单的<script>,把教程里的例子模仿一遍,理解用法.不推荐上来就 ...
- mardown文档的用法
<hr>分割换行符<br>分隔符 <ul> <li></li></ul>无序标签 <ol><li>< ...
- C语言腾讯课堂(一)
腾讯课堂:c语言从零到精通 1. 从第一个例子开始 #include <stdio.h> int main(void) { printf("hello, qin men \n&q ...