Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学
2015-11-01 14:50
507 查看
B. The Monster and the Squirrel
Time Limit: 20 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/contest/592/problem/BDescription
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?
[b]Input[/b]
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.
[b]Output[/b]
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.
[b]Sample Input[/b]
5
[b]Sample Output[/b]
9
HINT
[b]题意[/b]
每个点依次和其他点连线,如果这条直线连接的过程中,和另外一条直线相交的话,就会被截断
然后问你,正n边形,被截成了多少块
[b]题解:[/b]
打表吧,在纸上画画,然后就找到规律了……(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.
[b]代码[/b]
#include<iostream> using namespace std; int main() { long long n; cin>>n; cout<<(n-2LL)*(n-2LL)<<endl; }
相关文章推荐
- InputSplit—>RecordReder—>map(key,value,context)的过程解析
- POJ 1947 Rebuilding Roads(树形DP)
- NGUI简单的UI功能操作
- IOS-UITableView上的纯代码实现
- cf#328-B. The Monster and the Squirrel-水题+数学规律
- HDU 5531 Rebuild 相切的圆们
- EasyUI - DataGrid 组建 - [ 样式功能 ]
- handler更新UI主线程
- uestcoj Huatuo's Medicine 1226 (简单题)
- uva 1612——Guess
- Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel
- priority_queue的用法
- IDDFS--UESTC - 577 分数拆分
- Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel(数学规律)
- Codeforces Round #328 (Div. 2)_B. The Monster and the Squirrel
- Codeforces Round #328 (Div. 2)_B. The Monster and the Squirrel
- 清除UITableView底部多余的分割线
- 03-32位UUID和封装Map对象到指定类型的Bean中
- Packet for query is too large (1986748 > 1048576). You can change this value on the server by
- UESTC Pick The Sticks (背包变形)