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 inputtry:line = raw_input()except:breakways_of_cutting = int(line)

转载于:https://www.cnblogs.com/qscqesze/p/5958569.html

Xtreme9.0 - Mr. Pippo's Pizza 数学相关推荐

  1. Xtreme9.0 - Light Gremlins 容斥

    Xtreme9.0 - Light Gremlins 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenge ...

  2. 取余运算怎么算_TensorFlow2.0(2):数学运算

    点击"机器学习算法与Python实战","置顶"公众号 重磅干货,第一时间送达 TensorFlow2.0(1):基本数据结构--张量 1 基本运算:(+.-. ...

  3. Xtreme9.0 - Block Art 线段树

    Block Art 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/block-art Descr ...

  4. 极限中0除以常数_考研数学极限重难点讲解003期【无穷小量和无穷大量】

    01 无穷小量与无穷大量的定义极限 1.无穷小量 定义1:以0为极限的变量,称为无穷小量.即若则称时f(x)为无穷小量,常数0也是无穷小.这里的可以是或是中的某一个,以下类似. 2.无穷大量 定义2: ...

  5. 漏洞poc和漏洞利用_带HTML的PowershellHTML空白空间隐写术和二进制漏洞利用交付[PoC]

    漏洞poc和漏洞利用 实用隐写术 (Practical Steganography) A few years ago I came across a very academic challenge: ...

  6. 508人决战,北大占绝对优势,2021阿里全球数学决赛真题发布!

    转自:机器之心 5 大赛道的 25 道决赛试题已正式公布,你都能看懂吗? 6 月 27 日 0 点,2021 阿里巴巴数学竞赛总决赛结束.今年,508 位决赛入围选手线上奋战 8 小时,角逐最后的奖项 ...

  7. 神经网络收敛标准与准确率之间的数学关系

    制作一个带一个3*3卷积核的神经网络,测试集是minst的0和2图片集,将28*28的图片缩小成9*9,隐藏层30个节点所以网络的结构是 S(minst0)-(con3*3)49-30-2-(1,0) ...

  8. 到现在才理解高斯分布的均值与方差为什么是0和1

    问题的来源,如图所示:为什么标准正态分布的期望值0,方差为1呢,如果是针对x变量,期望值为0可以理解,那么方差为1怎么理解呢,显然不可能为1,如果针对y变量,显然所有值都大于0,怎么会期望值会大于0呢 ...

  9. 改变世界的5大常数,学过数学的人,这一辈子都不会忘记!

    全世界只有3.14 % 的人关注了 青少年数学之旅 何谓数学? 数学家Eduardo曾这样回答 "数学是永恒,是真理,是一切的答案." 回首往昔 数学始终伴随我们左右 纵横交错的几 ...

最新文章

  1. 玩了一个人脸识别登录
  2. Docker 修改镜像源地址
  3. 寻求最佳开发模式,免得落得“精”尽人亡
  4. 洛谷 1195 口袋的天空
  5. MATLAB——nctoolbox安装及使用
  6. linux网络编程之怎么配置好unp.h文件
  7. 谷歌 | 多任务学习,如何挑选有效的辅助任务?只需一个公式!
  8. javascript中动态加载js、vbs脚本或者css样式表
  9. ie 无人操作自动关闭_win7的IE自动关闭如何解决?
  10. Eclipse — 如何快速生成servlet类和配置文件(web里)
  11. 中国管理实践的大趋势
  12. clear linux
  13. Peekaboo——代码规范、冲刺任务与计划
  14. OTHER:环比与同比
  15. matlab怎么加采样开关,开关量采集模块怎么使用?
  16. 【应届生笔试资料分享二】中国农业银行相关介绍汇总
  17. 第世界上第一代电子计算机,第一代电子计算机
  18. python自己做课程表_Kivy做一个课程表App(上)
  19. UE5 官方案例Lyra 全特性详解 13.背包系统Inventory System 2
  20. cenntos系统配置dns地址_localhost

热门文章

  1. SCT2450,SCT2450Q,降压DCDC
  2. android queries属性
  3. 关于CSDN, cnblog, iteye和51cto四个博客网站的比较与分析
  4. 彼岸夏花(一个爱与救赎的凄美故事)
  5. Ubuntu 18.04 LTS \n \l 配置网卡IP
  6. C#中 out 参数的使用
  7. Arduino-超声波测距仪-实现近距离蜂鸣器报警
  8. 全站仪,激光跟踪仪,激光干涉仪,激光测距仪
  9. 华为网络----OSPF重分发与优化(二)
  10. 某音直播协议实现技术探讨