(第八场)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. ...
随机推荐
- stream3
import java.util.function.Consumer; import java.util.function.IntConsumer; public class ConsumerTest ...
- CentOS 6.7 安装配置 nagios-server
作者博文地址:https://www.cnblogs.com/liu-shuai/ 一.简介 Nagios是一款开源的免费网络监视工具,能有效监控Windows.Linux和Unix的主机状态, ...
- 使用selenium时碰到的某一个坑
如图:
- e.target和e.event和event.srcElement
e.target 是目标对象,e.event是目标所发生的事件,event.srcElement捕获当前事件作用的对象 1. $(function(){ $("li:has(ul)" ...
- HTTP和HTTPS的区别?
HTTP1.1(Hypertext Transfer Protocol Vertion 1.1)超文本传输协议-版本1.1它是用来在Internet上传送超文本的传送协议.它是运行在Tcp/Ip协议族 ...
- select(有局限性),jq循环添加select的值
加载的时候改变select的默认值,只需改变select的value值 $("#one").val(@ViewBag.val);//@ViewBag.val是要默认选中的值的val ...
- MyBatis 中 sqlmapconfig核心标签说明以及配置
文件介绍 对于 MyBatis 最核心的全局配置文件是 sqlmapConfig.xml 文件,其中包含了数据库的连接配置信息.Mapper 映射文件的加载路径.全局参数.类型别名等. 配置项详解 标 ...
- python占位符%s,%d,%r,%f
input接收的所有输入默认都是字符串格式 1.%s代表字符串占位符 conn, client_addr = phone.accept() print(conn) print(client_addr) ...
- html-框架标签的使用
<frameset> - rows:按照行进行划分 ** <frameset rows="80,*"> - cols:按照列进行划分 ** <fram ...
- ECharts动态数据加载
最近有用到ECharts做可视化报表,小结一下 一.准备数据 1.官网下载echarts.min.js 2.引入jquery.js 3.请求用的json数据 { "list":[ ...