博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学
阅读量:6705 次
发布时间:2019-06-25

本文共 2265 字,大约阅读时间需要 7 分钟。

B. The Monster and the Squirrel

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/592/problem/B

Description

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.

Sample Input

5

Sample Output

9

HINT

 

题意

每个点依次和其他点连线,如果这条直线连接的过程中,和另外一条直线相交的话,就会被截断

然后问你,正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
using namespace std;int main(){ long long n; cin>>n; cout<<(n-2LL)*(n-2LL)<

 

转载地址:http://ujflo.baihongyu.com/

你可能感兴趣的文章
如何获取jqGrid中选择的行的数据
查看>>
Android 获取自带浏览器上网记录
查看>>
c++ 静态持续变量
查看>>
MFC超链接静态类的使用
查看>>
我所遭遇过的游戏中间件---SpeedTree
查看>>
android:versionCode和android:versionName 用途(转)
查看>>
Fragment Transactions & Activity State Loss
查看>>
jQuery插件 -- 表单验证插件jquery.validate.js
查看>>
我的MYSQL学习心得(十四) 备份和恢复
查看>>
nodejs express 安装
查看>>
flume-ng-elasticsearch 索引时间命名问题(时区和时间格式)
查看>>
PE文件结构学习
查看>>
在对listctrl的控件进行重载的过程中,GetHeaderCtrl()返回NULL的问题
查看>>
WEB网站前端性能分析相关
查看>>
sql server2008系统表详细说明sys.开头的表
查看>>
Python基础(9)--正则表达式
查看>>
解决Installation error: INSTALL_FAILED_VERSION_DOWNGRADE错误
查看>>
os 计算机的启动
查看>>
C++Vector使用方法
查看>>
字符串逆序输出
查看>>