日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Xtreme9.0 - Mr. Pippo's Pizza 数学

發布時間:2024/3/12 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 inputtry:line = raw_input()except:breakways_of_cutting = int(line)

轉載于:https://www.cnblogs.com/qscqesze/p/5958569.html

總結

以上是生活随笔為你收集整理的Xtreme9.0 - Mr. Pippo's Pizza 数学的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。