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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. codeforces 592B The Monster and the Squirrel

    题目链接:http://codeforces.com/contest/592/problem/B 题目分类:数学,找规律 题目分析:重要的是画图找规律   代码: #include<bits/s ...

  4. Codeforces Round #328 (Div. 2)

    这场CF,准备充足,回寝室洗了澡,睡了一觉,可结果...   水 A - PawnChess 第一次忘记判断相等时A先走算A赢,hack掉.后来才知道自己的代码写错了(摔 for (int i=1; ...

  5. codeforces 592B/C

    题目链接:http://codeforces.com/contest/592/problem/B B. The Monster and the Squirrel time limit per test ...

  6. 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 ...

  7. Squirrel: 通用SQL、NoSQL客户端

    安装 配置数据库 配置驱动 配置连接 如果你的工作中,需要使用到多个数据库,又不想在多种客户端之间切换来切换去.那么就需要找一款支持多数据库的客户端工具了.如果你要连接多个关系型数据库,你就可以使用N ...

  8. Font Squirrel

    Font Squirrel FontSquirrel:国外免费字体下载网是一个提供高质量商业字体下载网站,提供海量的英文字体库,用户可以随意下载并应用于各种商业用字,无需考虑其版权问题. 官网地址:h ...

  9. 使用Squirrel创建基于Electron开发的Windows 应用安装包

    我们把自己开发的Electron应用发布之前,需要把app打包成简单的安装包,这样app更容易被获取,以此来发布我们的应用.我们可以参考Wix或其他的安装程序,但是对于Electron应用更好的打包程 ...

随机推荐

  1. java调用DLL,打印二维码标签

    package com.ian.das.controller; import java.util.List; import org.xvolks.jnative.JNative; import org ...

  2. 负载均衡框架 ribbon 二

    Ribbon 负载均衡机制 官方文档地址:https://github.com/Netflix/ribbon/wiki/Working-with-load-balancers 1. Ribbon 内置 ...

  3. java的权限控制

    java有三个权限的关键字:public.private.protected public:对任何人都可以使用. private:只有类的创建者和内部的方法可以使用,它的导出类也不可以访问. prot ...

  4. [每日一题系列] LeetCode 1071. 字符串的最大公因子

    题目 对于字符串 S 和 T,只有在 S = T + ... + T(T 与自身连接 1 次或多次)时,我们才认定 "T 能除尽 S". 返回最长字符串 X,要求满足 X 能除尽 ...

  5. utuntu sever1804显示中文putty可以输入中文

    默认情况下,putty连接ubuntu server以后,哪怕设置的Utf-8的连接,也是无法显示中文的. 应该是ubuntu服务器端,没有字库的问题. 如果在putty显示和输入中文呢,因为配置信息 ...

  6. 解决 unable to lock the administration directory (/var/lib/dpkg/) 问题

    阿里开源镜像站提供了raspbian的软件包镜像,国内的用户可以选择改用阿里镜像站作为更新源. 但是在更换源之后,执行 sudo apt-get update && apt-get u ...

  7. 五分钟学Java:如何才能学好Java Web里这么多的技术

    原创声明 本文作者:黄小斜 转载请务必在文章开头注明出处和作者. 系列文章介绍 本文是<五分钟学Java>系列文章的一篇 本系列文章主要围绕Java程序员必须掌握的核心技能,结合我个人三年 ...

  8. Intel优化Gen7驱动代码 Geekbench 5性能猛增

    Linux下缺少大量开发.支持是会导致各种奇葩的错误的,Intel日前就提交了一个代码修复,22nm Ivybridge及Haswell处理器的GeekBench 5的性能就提升了330%. 3.3倍 ...

  9. Spring中的JdbcTemplate的使用

    一.jdbcTemplate的作用 它就是用于和数据库交互的,实现对表的crud.与dbutils相似 二.JdbcTemplate的使用 <dependency> <groupId ...

  10. Spark入门(五)--Spark的reduce和reduceByKey

    reduce和reduceByKey的区别 reduce和reduceByKey是spark中使用地非常频繁的,在字数统计中,可以看到reduceByKey的经典使用.那么reduce和reduceB ...