B. The Monster and the Squirrel
B. The Monster and the Squirrel
Ari the monster always wakes up very early with the first ray of the
sun and the first thing she does is feeding her squirrel.Ari draws a regular convex polygon on the floor and numbers it’s
vertices 1, 2, …, n in clockwise order. Then starting from the
vertex 1 she draws a ray in the direction of each other vertex. The
ray stops when it reaches a vertex or intersects with another ray
drawn before. Ari repeats this process for vertex 2, 3, …, n (in
this particular order). And then she puts a walnut in each region
inside the polygon.
Ada the squirrel wants to collect all the walnuts, but she is not
allowed to step on the lines drawn by Ari. That means Ada have to
perform a small jump if she wants to go from one region to another.
Ada can jump from one region P to another region Q if and only if P
and Q share a side or a corner.Assuming that Ada starts from outside of the picture, what is the
minimum number of jumps she has to perform in order to collect all the
walnuts?Input The first and only line of the input contains a single integer n
(3 ≤ n ≤ 54321) - the number of vertices of the regular polygon drawn
by Ari.Output Print the minimum number of jumps Ada should make to collect
all the walnuts. Note, that she doesn’t need to leave the polygon
after.
Examples
Input
5
Output
9
Input
3
Output
1
Note One of the possible solutions for the first sample is shown on
the picture above.
题解如下
解题说明:题目的意思是每个点依次和其他点连线,如果这条直线连接的过程中,和另外一条直线相交的话,就会被截断。然后问你,正n边形,被截成了多少块。此题可以考虑用找规律的方法,先从边数少的n边型开始,计算数目,最后发现规律,值为(n-2)*(n-2)。网上有详细证明过程:
After drawing the rays from the first vertex (n - 2) triangles are formed. The subsequent rays will generate independently sub-regions in these triangles. Let’s analyse the triangle determined by vertices 1, i, i + 1, after drawing the rays from vertex i and (i + 1) the triangle will be divided into (n - i) + (i - 2) = n - 2 regions. Therefore the total number of convex regions is (n - 2)2

If the squirrel starts from the region that have 1 as a vertex, then she can go through each region of triangle (1, i, i + 1) once. That implies that the squirrel can collect all the walnuts in (n - 2)2 jumps.
思路如下
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
long long n;
cin>>n;
cout<<(n-2)*(n-2)<<endl;
return 0;
}
B. The Monster and the Squirrel的更多相关文章
- Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学
B. The Monster and the Squirrel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...
- Codeforces Round #328 (Div. 2)_B. The Monster and the Squirrel
B. The Monster and the Squirrel time limit per test 1 second memory limit per test 256 megabytes inp ...
- codeforces 592B The Monster and the Squirrel
题目链接:http://codeforces.com/contest/592/problem/B 题目分类:数学,找规律 题目分析:重要的是画图找规律 代码: #include<bits/s ...
- Codeforces Round #328 (Div. 2)
这场CF,准备充足,回寝室洗了澡,睡了一觉,可结果... 水 A - PawnChess 第一次忘记判断相等时A先走算A赢,hack掉.后来才知道自己的代码写错了(摔 for (int i=1; ...
- codeforces 592B/C
题目链接:http://codeforces.com/contest/592/problem/B B. The Monster and the Squirrel time limit per test ...
- Codeforces Round #328 (Div. 2) B
B. The Monster and the Squirrel time limit per test 1 second memory limit per test 256 megabytes inp ...
- Squirrel: 通用SQL、NoSQL客户端
安装 配置数据库 配置驱动 配置连接 如果你的工作中,需要使用到多个数据库,又不想在多种客户端之间切换来切换去.那么就需要找一款支持多数据库的客户端工具了.如果你要连接多个关系型数据库,你就可以使用N ...
- Font Squirrel
Font Squirrel FontSquirrel:国外免费字体下载网是一个提供高质量商业字体下载网站,提供海量的英文字体库,用户可以随意下载并应用于各种商业用字,无需考虑其版权问题. 官网地址:h ...
- 使用Squirrel创建基于Electron开发的Windows 应用安装包
我们把自己开发的Electron应用发布之前,需要把app打包成简单的安装包,这样app更容易被获取,以此来发布我们的应用.我们可以参考Wix或其他的安装程序,但是对于Electron应用更好的打包程 ...
随机推荐
- linux yum安装MySQL5.6
1.新开的云服务器,需要检测系统是否自带安装mysql # yum list installed | grep mysql 2.如果发现有系统自带mysql,果断这么干 # yum -y remove ...
- 使用 ALSAlib 播放 wav
在 ARM 2440 开发板上正常播放 16bit 44100 采样率的wav , 为了程序简单,没有判断返回值. 补充,在 ubunto 上也能正常播放. 编译方法: arm-linux-gcc ...
- Java自学路线图之Java系统自学
Java自学不是一朝一夕的事情.可以采用"懒开始"的方法,但是必须要坚持下去,才能真正自学Java掌握编程技术.那些企图学几天去包装一下找工作的,请绕道.如果你下定决心自学Java ...
- 写于疫情期间的一个plantUML例子
@startuml 这几天的正经事 start repeat if(思维清晰) then (yes) :刷题; else (no) if(想写程序) then (yes) :调项目; else (no ...
- ES6: let 与 const
ES2015(ES6) 新增加了两个重要的 JavaScript 关键字: let 和 const. let 声明的变量只在 let 命令所在的代码块内有效. const 声明一个只读的常量,一旦声明 ...
- Linux系统之LNMP及nginx反向代理实现
1.编译安装LNMP,并安装wordpress 首先准备环境,编译安装LNMP可以是多台主机,也可以是单台主机,把nginx,mysql,php都集中安装在一个主机上:我这里以一台主机为例吧!! 一. ...
- LSTM + linear-CRF序列标注笔记
CRF 许多随机变量组成一个无向图G = {V, E},V代表顶点,E代表顶点间相连的边, 每个顶点代表一个随机变量,边代表两个随机变量间存在相互影响关系(变量非独立), 如果随机变量根据图的结构而具 ...
- Alterations of brain quantitative proteomics profiling revealed the molecular mechanisms of diosgenin against cerebral ischemia reperfusion effects(大脑的定量蛋白质组学揭示了薯蓣皂苷元对脑缺血再灌注效应的分子机制)
文献名:Alterations of brain quantitative proteomics profiling revealed the molecular mechanisms of dios ...
- thinkphp5.0.*命令执行批量脚本
import requests import Queue import threading import time user_agent = "Mozilla/5.0 (Windows NT ...
- python https请求报错:SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED]
python爬虫,使用requests库发送https请求报错:SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 解决方法: imp ...