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应用更好的打包程 ...
随机推荐
- 关于有趣的windows.h
system 函数: 这个函数差不多就是调用 cmd (命令提示符). 当然,不一定要在程序中调用,用 txt 打入文本( 不用加system() )后改后缀名为 cmd 后运行即可. Win 键 + ...
- Ubuntu18.04LTS 文件系统简记
Ubuntu18.04LTS 文件系统 了解Linux文件系统是熟悉掌握使用Linux系统的第一步 首先安装名为tree的工具 sudo apt install tree 运行 tree --help ...
- 使用R进行空间自相关检验
「全局溢出」当一个区域的特征变化影响到所有区域的结果时,就会产生全局溢出效应.这甚至适用于区域本身,因为影响可以传递到邻居并返回到自己的区域(反馈).具体来说,全球溢出效应影响到邻居.邻居到邻居.邻居 ...
- jenkins-构建job成功后自动打tag到git仓库
需求:最近开发同事提出了个要求,每当Jenkins执行上线部署完成后,对当前代码进行自动打TAG到git仓库中,且只有当部署成功后才进行打TAG,防止构建失败也进行打过多的垃圾tag,然后便于下次进行 ...
- 教你高效使用数据可视化BI软件创建医院卫生耗材运营监控大屏
灯果数据可视化BI软件是新一代人工智能数据可视化大屏软件,内置丰富的大屏模板,可视化编辑操作,无需任何经验就可以创建属于你自己的大屏.大家可以在他们的官网下载软件. 本文以医院卫生耗材运营监控大屏 ...
- 有了这套微信小程序x5调试,调试一些简单的开发者工具调试不了的功能不成问题!!!!
1.首先我们需要打开微信 TBS 调试 地址是:http://debugx5.qq.com 2.然后打开手机 打开开发者模式,打开 USB 调试 3.然后 在谷歌浏览器地址栏输入 chrome://i ...
- 网络工程师和Linux运维工程师有什么区别?学哪个比较好?
网络工程师和Linux运维工程师有什么区别?学哪个比较好? 机缘巧合下,我进入了一家从事vpn与系统集成的公司,很感谢公司能留下我这个非网络工程专业的毕业生,从对网络一窍不通,慢慢可以自己独立完成工作 ...
- 前端构建工具gulpjs的使用介绍及技巧【转载】
转载至:http://www.cnblogs.com/2050/p/4198792.html gulpjs是一个前端构建工具,与gruntjs相比,gulpjs无需写一大堆繁杂的配置参数,API也非常 ...
- Java8 Stream流
第三章 Stream流 <Java8 Stream编码实战>的代码全部在https://github.com/yu-linfeng/BlogRepositories/tree/master ...
- Python GUI wxPython StaticText控件背景色透明
import wx class TransparentStaticText(wx.StaticText): """ 重写StaticText控件 "" ...