B. The Monster and the Squirrel

article/2025/9/11 1:05:18

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;
}

http://chatgpt.dhexx.cn/article/63Yomk2l.shtml

相关文章

Springboot整合squirrel-foundation状态机

目录 一. 快速入门 1 . maven 2 . 快速开始 3 . Fluent Api 4 . 状态机四要素 5 . 状态机构建器 6 . 状态机转换操作(代码配置方式) 7 . 状态机转换操作(注解声明方式) 8 . 上下文不敏感状态机 二 : 使用注意事项 P1 : 异常 : StateMachineBuilderImpl cannot fi…

Hive的客户端界面工具–SQuirrel SQL Client--详细安装以及连接Hive过程

SQuirrel SQL Client是一款支持Hive的可视化工具&#xff0c;是市面上少数支持Hive中比较好用的&#xff0c;看下如何安装使用吧&#xff0c;下面是非常详细的安装过程。 1.下载客户端 SQuirrel SQL Client的官网及下载地址为&#xff1a;http://squirrel-sql.sourceforge.ne…

Linux安装SQuirreL SQL Client

环境和准备 操作系统&#xff1a; Ubuntu 20.04SQuirreL&#xff1a; squirrel-sql-snapshot-20220326_1238-standard.jarDb2 driver&#xff1a; db2jcc4.jardb2jcc_license_cu.jar MySQL driver&#xff1a; mysql-connector-java-8.0.27.jar 下载和安装 首先下载SQuirreL…

智能优化算法之松鼠算法(Squirrel search algorithm)

文章目录 背景Squirrel search algorithm(SSA)SSARandom initialization&#xff08;随机初始化&#xff09;Fitness evaluation&#xff08;适应值评价&#xff09;Sorting, declaration and random selection&#xff08;排序、声明和随机选择&#xff09;Generate new locat…

electron打包遇到 Making for target: squirrel - On platform: win32 - For arch: x64错误

上面横线处是出现错误的位置。报错的原因如下&#xff1a; 1、package.json的“author”和“description”在打包时是必填内容&#xff0c;随便填些内容即可打包成功。 2、和项目的绝对路径有关&#xff0c;项目的绝对路径不能出现中文&#xff0c;否则在红线处会报错。

WPF 使用Squirrel自动更新应用

前言 本文简单的介绍了如何使用 Squirrel 来为 WPF 客户端 进行自动检查更新。 Squirrel git 地址 &#xff1a;http:// https://github.com/Squirrel/Squirrel.Windows 本文使用了 Visual Studio 2022 进行演示讲解。 参考英文博客&#xff1a; https://intellitect.com/d…

SQuirrel SQL Client的安装

如果您的工作要求您在一天之中连接许多不同的数据库 &#xff08;oracle、DB2、mysql、postgresql、Sql Server等等&#xff09;&#xff0c;或者你经常需要在多个不同种类的数据库之间进行数导入导出。那么SQuirreL SQL Client 将会是比较理想的数据库客户端链接工具。 简单介…

数据库管理工具——SQuirreL SQL Client使用入门

如果您的工作要求您在一天之中连接许多不同的数据库 &#xff08;oracle、DB2、mysql、postgresql、Sql Server等等&#xff09;&#xff0c;或者你经常需要在多个不同种类的数据库之间进行数导入导出。那么SQuirreL SQL Client 将会是比较理想的数据库客户端链接工具。 简单介…

SQuirrel连接hive配置

1. 简介 最近由于大数据部门相关同事离职&#xff0c;不得不研究一下大数据相关组件&#xff0c;今天成功安装配置Hive&#xff0c;简单记录&#xff0c;一是为了加深印象&#xff0c;二是为以后备用&#xff0c;三是为大家提供参考&#xff0c;避免少踩坑。 在Hive的官网上…

FSM——squirrel状态机使用

FSM——squirrel状态机使用 1 FSM介绍 1.1 概念 FSM&#xff08;finite state machine&#xff09;:有限状态机 是表示有限个状态以及在这些状态之间的转移和动作等行为的数学模型。核心内容&#xff1a;有限个状态、通过外部操作引起状态的转移。用来对状态的流转进行解耦&a…

Squirrel SQL客户端使用图解

一、Squirrel简介 Squirrel是一个连接数据库的客户端工具&#xff0c;一般支持JDBC的数据库都可以用它来简介&#xff0c;如连接MySQL。 二、安装准备 下载jar包&#xff1a;squirrel-sql-3.7.1-standard.jar 三、安装 ①进入squirrel-sql-3.7.1-standard.jar文件所在的目录…

完成GitHub上squirrel 的运行(数据库的模糊测试)

文章目录 一、squirrel的介绍squirrel链接建议下载Ubuntu 18.04编译安装clang/llvm&#xff08;建议9.0以上&#xff09;将squirrel的文件下载到Ubuntu上下载docker&#xff08;建议按照dockerfile步骤直接在外部搭建环境&#xff09;Dockerfile创建镜像按照dockfile搭建时时有…

连接HiveServer2的图形化工具SQuirrel和Dbeaver

文章目录 SQuirrel SQL Client简介视频演示安装SQuirrel SQL Client启动hdfs和hiveserver2配置SQuirrel SQL Client使用SQuirrel SQL Client访问hive使用Cloudera提供的hive连接驱动进行连接Dbeaver的安装及使用 本文介绍的工具可以通过下面链接下载&#xff1a; 链接&#xff…

squirrel校园二手交易平台

##squirrel校园二手交易平台 &#xff08;适合寻找SSM项目练手的你。&#xff09; 问题汇总&#xff1a; &#xff08;朋友毕设用到了这个二手平台&#xff0c;他自己把后台优化了&#xff0c;我又帮忙实现了一部分功能&#xff0c;只能做到这里了。有兴趣的&#xff0c;自行优…

squirrel sql 使用

前置 安装jdk&#xff08;1.8版本即可&#xff09; 1、官网下载squirrel sql client jar https://sourceforge.net/projects/squirrel-sql/ 2 运行java -jar squirrel-sql-3.6-standard.jar安装 jar包 注意3.0的版本要JDK1.6以上 这里可以改安装目录 这里可以选择插件&#…

[squirrel使用]--Windows安装详解

squirrel在windows下的安装文档 一&#xff0e;下载安装 从网址http://www.squirrelsql.org/下载相应版本的squirrel的安装jar包&#xff0c;比如下载squirrel-sql-3.7-standard.jar双击安装&#xff0c;出现如下安装界面&#xff0c;下一步开始安装 二&#xff0e;配置连接p…

Squirrel状态机-从原理探究到最佳实践

作者&#xff1a;京东物流 郑朋辉 1 简介 Squirrel状态机是一种用来进行对象行为建模的工具&#xff0c;主要描述对象在它的生命周期内所经历的状态&#xff0c;以及如何响应来自外界的各种事件。比如订单的创建、已支付、发货、收获、取消等等状态、状态之间的控制、触发事件…

squirrel(松鼠)状态机的介绍及使用

squirrel&#xff08;松鼠&#xff09;状态机 依赖 <dependency><groupId>org.squirrelframework</groupId><artifactId>squirrel-foundation</artifactId><version>0.3.8</version> </dependency>状态机描述 参考&#xf…

将图片转换为base64编码

1、base64编码简介 Base64是一种可逆的编码方式&#xff0c;简单来讲就是一种将64个Ascii字符来表示成二进制数据的方法。主要用于将不可打印的字符转换成可打印字符&#xff0c;或者简单的说将二进制数据编码成Ascii字符。Base64是网络上最常用的传输8bit字节数据的编码方式之…

前端理解base64

一、背景&#xff1a;ascii码 字符>二进制 计算机中所有数据的存储都是以二进制模式&#xff0c;比如想要存储abcd需将其转化为二进制&#xff0c;具体用哪些二进制来表示哪个符号*&#xff0c;有一个统一的编码规则&#xff0c;这就是ascii。 ASCII 码使用指定的7 位或8…