Xtreme9.0 - Mr. Pippo's Pizza 数学
Mr. Pippo's Pizza
题目连接:
https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/mr-pippos-pizza
Description
Mr. Pippo wants to start a new pizza shop. Everything about his pizzas is unique — the recipe is unique, the taste is unique, and even the shape of pizzas is unique. Instead of having a round shape like every other pizza, Mr. Pippo makes his pizzas in polygon shapes. For example, he can make his pizzas in a triangular shape or in a pentagonal shape.
Before serving a pizza, Mr. Pippo cuts it into triangular pieces. However, there are different ways he can cut the pizza. For example, a pentagonal pizza can be cut in five different ways as shown in the following figure. Each day, Mr. Pippo chooses a particular shape which can only be cut in an odd number of ways. Note that all the five cuts in the figure happen to be rotationally symmetric, but each of them is considered distinct.
Different ways a pentagonal pizza can be cut
Figure: Different ways a pentagonal pizza can be cut
Your task in this problem is to determine the shape of the pizza. Given the number of ways the pizza can be cut, you have to determine how many sides the pizza has.
Further clarification regarding the ways a pizza can be cut is given below:
A pizza can only be cut by connecting two vertices,
Two cuts on the pizza cannot cross each other, and
For an n-polygon there would be exactly (n-3) cuts which divide the pizza into (n-2) pieces.
Input
There will be up to 100 lines given where each line represents one test case. For each test case, the number of ways the pizza can be cut will be given. The number will be always odd and can be up to 308 digits long. The input is finished when end-of-file is reached.
Output
For each test case, print on a single line the number of sides the pizza has.
Sample Input
1
5
Sample Output
3
5
Hint
题意
给你把正n边形全部切成三角形的方案数,让你求这个是正多少边形。
题解
推公式,可以发现答案是
(2n-4)!/(n-1)!(n-2)!
代码
from __future__ import print_function
from math import factorial
# get first line of input
ways_of_cutting = int(raw_input())
# check if there is a remaining line of input (should return "None" and exit if EOF reached)
while ways_of_cutting:
# print("ways_of_cutting: {}".format(ways_of_cutting))
if ways_of_cutting == 1:
print(3)
elif ways_of_cutting == 2:
print(4)
elif ways_of_cutting == 5:
print(5)
else:
for n in range(5, 1000):
if factorial(2 * (n - 2)) / (factorial(n - 1) * factorial(n - 2)) == ways_of_cutting:
print(n)
break
# get next line of input
try:
line = raw_input()
except:
break
ways_of_cutting = int(line)
Xtreme9.0 - Mr. Pippo's Pizza 数学的更多相关文章
- Xtreme9.0 - Communities 强连通
Xtreme9.0 - Communities 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/c ...
- Xtreme9.0 - Light Gremlins 容斥
Xtreme9.0 - Light Gremlins 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenge ...
- IEEEXtreme Practice Community Xtreme9.0 - Digit Fun!
Xtreme9.0 - Digit Fun! 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/di ...
- Xtreme9.0 - Taco Stand 数学
Taco Stand 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/taco-stand Des ...
- Xtreme9.0 - Block Art 线段树
Block Art 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/block-art Descr ...
- Xtreme9.0 - Pattern 3 KMP
Pattern 3 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/car-spark Descr ...
- Xtreme9.0 - Car Spark 动态规划
Car Spark 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/car-spark Descr ...
- Xtreme8.0 - Back to Square 1 数学
Back to Square 1 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/back-to- ...
- IEEEXtreme Practice Community Xtreme9.0 - Dictionary Strings
Dictionary Strings 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/dictio ...
随机推荐
- 高并发数据库之MySql性能优化实战总结
向MySQL发送一个请求时MySQL具体的操作过程 慢查询 1.慢查询 SHOW VARIABLES LIKE '%quer%' 索引优化技巧 1.对于创建的多列索引(复合)索引,只要查询条件使用了最 ...
- python 基础知识 列表的 增删改查 以及迭代取值
""" python 列表 通用方法 元组.数组.字典 取值方法 [] 列表中可以存储不同类型的数据 函数 封装了独立的功能可以直接调用 函数名(参数) 方法 和函数类似 ...
- Floyd判圈算法 UVA 11549 - Calculator Conundrum
题意:给定一个数k,每次计算k的平方,然后截取最高的n位,然后不断重复这两个步骤,问这样可以得到的最大的数是多少? Floyd判圈算法:这个算法用在循环问题中,例如这个题目中,在不断重复中,一定有一个 ...
- 由于找不到MSVCP20.dll,无法继续执行代码
系统:win10 专业版,刚升级win10没几天 mysql 5.7.21 解压安装,初始化时报错,错误如图: 一.查找错误原因 参考:MySQL安装使用遇到的问题, 找到微软中文官方网站,搜索 ms ...
- Linux输出重定向>和>>的区别是什么
[简介:>与>>的区别] 1 > 是定向输出到文件,如果文件不存在,就创建文件:如果文件存在,就将其清空:一般我们备份清理日志文件的时候,就是这种方法:先备份日志,再用`& ...
- 【ARTS】01_07_左耳听风-20181224~1230
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- IE下常见兼容性问题总结
概述 本小菜平时主要写后台程序,偶尔也会去写点前端页面,写html.css.js的时候,会同时开着ie6.ie7.ie8.ie9.chrome.firefox等浏览器进行页面测试,和大部分前端开发一样 ...
- PHP URL中包含中文,查看时提示404
使用Microsoft Web Platform在IIS里配置安装一个wordpress,一切顺利. 当添加一片文章时,自动生成URL类似如下: http://localhost/wordpress/ ...
- ASP.NET MVC环境下实现一个网站多个网站模板的方法
asp.net mvc下实现多个网站模板的方法,让ASP.NET一个网站有多套网站模板,不用的场景下使用不用的mvc 模版. 比如有默认,红,蓝,绿几种网站模板,客户可以根据自己喜好选择自己喜欢的网 ...
- delete/truncate/drop table的区别以及锁在这里的角色
数据库删除语句 Drop/Delete/Truncate比较 Delete :删除数据表中的行(可以删除某一行,也可以在不删除数据表的情况下删除所有行). 删除某一行:Delete from 数据表名 ...