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 ...
随机推荐
- AngularJS 启程二
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> ...
- 格式化 SQL 来提高效率
本文由 伯乐在线 - cucr 翻译,黄利民 校稿.未经许可,禁止转载!英文出处:msiman.ga.欢迎加入翻译小组. 背景 已格式化的SQL并不比未格式化SQL运行地更快.数据库可能真的不太在意你 ...
- 【Udacity并行计算课程笔记】- lesson 1 The GPU Programming Model
一.传统的提高计算速度的方法 faster clocks (设置更快的时钟) more work over per clock cycle(每个时钟周期做更多的工作) more processors( ...
- BurpSuite中的安全测试插件推荐
Burp Suite 是用于攻击web 应用程序的集成平台.它包含了许多工具,并为这些工具设计了许多接口,以促进加快攻击应用程序的过程.所有的工具都共享一个能处理并显示HTTP 消息,持久性,认证,代 ...
- 基于Consul的数据库高可用架构【转】
几个月没有更新博客了,已经长草了,特意来除草.本次主要分享如何利用consul来实现redis以及mysql的高可用.以前的公司mysql是单机单实例,高可用MHA加vip就能搞定,新公司mysql是 ...
- linux挂载mount参数优化
一. 1) 蓝色:表示经过优化的xfs mount时的参数defaults,noatime,nodiratime,nobarrier,discard,allocsize=256m,logbufs=8, ...
- 【最简单的方法】js判断字符串是否为JSON格式(20180115更新)
前言 针对 “js判断字符串是否为JSON格式” 这个问题,在网上查了许多资料,都没找到自己想要的答案. 但是看到这个帖子<js判断字符串是否为JSON格式>后,突然灵光一闪,想到一种很简 ...
- ntpdate时间同步
为什么需要网络同步时间: Linux服务器运行久时,系统时间就会存在一定的误差,一般情况下可以使用date命令进行时间设置,但在做数据库集群分片等操作时对多台机器的时间差是有要求的,此时就需要使用nt ...
- java.io.StreamCorruptedException: invalid stream header: EFBFBDEF 问题解决
错误方式 @Test public void testDeserializeTest() throws IOException, ClassNotFoundException { ByteArrayO ...
- laravel项目利用twemproxy部署redis集群的完整步骤
Twemproxy是一个代理服务器,可以通过它减少Memcached或Redis服务器所打开的连接数.下面这篇文章主要给大家介绍了关于laravel项目利用twemproxy部署redis集群的相关资 ...