Codeforces Round #328 (Div. 2)_B. The Monster and the Squirrel
1 second
256 megabytes
standard input
standard output
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?
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.
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.
5
9
3
1
One of the possible solutions for the first sample is shown on the picture above.
/*题目大意:给n个顶点、从每个顶点发出到其他各顶点的射线,且射线不相交、
* 问这样能将这n边形分成多少个部分 n>=3
*算法分析:给出几组样例: 顶点n 分成部分
3 1
4 4
5 9
6 16
7 25
8 36
不难发现规律 (n-4) * n + 4 (n>=4)
*/ #include <iostream>
#include <cstdio> using namespace std; int main() {
long long int n;
cin >> n;
if (n == 3)
cout << 1<< endl;
else
cout << (n-4) * n + 4<< endl; return 0;
}
Codeforces Round #328 (Div. 2)_B. The Monster and the Squirrel的更多相关文章
- 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 ...
- Codeforces Round #328 (Div. 2)
这场CF,准备充足,回寝室洗了澡,睡了一觉,可结果... 水 A - PawnChess 第一次忘记判断相等时A先走算A赢,hack掉.后来才知道自己的代码写错了(摔 for (int i=1; ...
- 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 ...
- Codeforces Round #328 (Div. 2) D. Super M 虚树直径
D. Super M Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/D ...
- Codeforces Round #328 (Div. 2) D. Super M
题目链接: http://codeforces.com/contest/592/problem/D 题意: 给你一颗树,树上有一些必须访问的节点,你可以任选一个起点,依次访问所有的必须访问的节点,使总 ...
- Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm
C. The Big Race Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/probl ...
- Codeforces Round #328 (Div. 2) A. PawnChess 暴力
A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...
- Codeforces Round #347 (Div.2)_B. Rebus
题目链接:http://codeforces.com/contest/664/problem/B B. Rebus time limit per test 1 second memory limit ...
- Codeforces Round #290 (Div. 2) _B找矩形环的三种写法
http://codeforces.com/contest/510/status/B 题目大意 给一个n*m 找有没有相同字母连起来的矩形串 第一种并查集 瞎搞一下 第一次的时候把val开成字符串了 ...
随机推荐
- (一)初识mybatis
Mybatis 是现在很多公司都选择使用的一个ORM(Object Relational Mapping)框架,所以是值得了解和学习一番的. MyBatis 是支持定制化 SQL.存储过程以及高级映射 ...
- Webpack 2 视频教程 013 - 自动分离 CSS 到独立文件
原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲 ...
- php使用websocket示例详解
一.php 中处理 websocket WebSocket 连接是由客户端主动发起的,所以一切要从客户端出发.第一步是要解析拿到客户端发过来的 Sec-WebSocket-Key 字符串. 复制代码代 ...
- 【原创】java NIO selector 学习笔记 一
能力有限,仅仅是自己看源码的一些笔记. 主要介绍 可选通道 和 选择器 选择键(SelectableChannel 和 Selector SelectionKey) 选择器(Selector) 选择 ...
- 快速恢复开发环境(系统还原后的思考,附上eclipse注释的xml配置文件)
1.Eclipse/Myeclipse的工作空间,不能放在系统盘 除非你的项目都有实时的云同步或SVN等,才能放在系统固态盘,不然你享受快速启动项目的同时,也需要承担系统奔溃后找不回项目的风险: 公司 ...
- MySQL字符串相关函数学习二
① LOWER(str):将字符串转为小写:与此函数具有相同作用的函数有LCASE() 如果参数是小写.数字或其他特殊字符,则返回原数据 ② LEFT(str, len):返回字符串str左边的len ...
- Tomcat 到底依赖JRE还是JDK
Tomcat 6.0 以上可以不再依赖JDK运行,直接使用JRE即可,但Tomcat 5.5以下,是必须安装JDK的. 这主要是由于,Tomcat 5.5及以下版本主要是依赖JDK去编译JSP文件生成 ...
- Android与javascript中事件分发机制的简单比较
在前面两篇博客中,我们讨论了Android中的事件分发的相关内容,那么在本篇博客当中,我们就简单探讨一下html或javascript中的事件分发机制,并进行简单的对比. 在前端中,对事件进行绑定有三 ...
- chromedriver与chrome版本映射列表
chromedriver与chrome版本映射列表: chromedriver版本 支持的Chrome版本 v2.30 v58-60 v2.29 v56-58 v2.28 v55-57 v2.27 v ...
- Ubuntu 16.04 升级 PHP 版本至 7.1
安装swoole扩展,怎么安装到7.0下去了,我本来编译的版本是7.19版本,但是没吃 升级步骤 $ sudo add-apt-repository ppa:ondrej/php $ sudo apt ...