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;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值