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<iostream>
using namespace std; int main()
{
long long n;
cin>>n;
cout<<(n-2LL)*(n-2LL)<<endl; }

最新文章

  1. MySQL 保留字
  2. Corn Fields——POJ3254状态压缩Dp
  3. 数据结构与算法(1)支线任务4——Lowest Common Ancestor of a Binary Tree
  4. js 函数前的+号
  5. Linux下安装vsftpd
  6. 20161106PM-Fiddler
  7. 3、android notification 详细用法
  8. Scala 深入浅出实战经典 第40讲:Set、Map、TreeSet、TreeMap操作代码实战
  9. 同域iframe的高度自适应
  10. javascript中字符串格式转化成json对象记录
  11. Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)
  12. 【HDOJ】2295 Radar
  13. Android 中的接口回调
  14. Android 开发笔记 “Sqlite数据库删除”
  15. C# Task 源代码(2)
  16. 关于Android log拿不到的情况
  17. 【官方文档】Nginx模块Nginx-Rtmp-Module学习笔记(三)流式播放Live HLS视频
  18. JavaScript 原型的深入指南
  19. WannaCry(永恒之蓝)病毒处理方法
  20. docker使用以及dockerfile编写

热门文章

  1. SwipeRefreshLayout的简要说明及使用demo
  2. ioctl()获取本地网卡设备信息
  3. Android欢迎界面的创建方法
  4. 《Python基础教程(第二版)》学习笔记 -&gt; 第十一章 文件和素材
  5. Tcpcopy简介与实战
  6. Tableau学习笔记之二
  7. 【STL】帮你复习STL泛型算法 一
  8. NGUI学习笔记-Label
  9. Java-note-调试小技巧
  10. OpenStack的Resize和冷迁移代码解析及改进