当前位置:网站首页>[punch in - Blue Bridge Cup] day 3 --- slice in reverse order list[: -1]
[punch in - Blue Bridge Cup] day 3 --- slice in reverse order list[: -1]
2022-06-30 03:35:00 【M4chael1】
subject 1 : Based on practice Yanghui triangle

Their thinking
” The first i+1 Line is (a+b)i The coefficients of the expansion of “, therefore Use C i k C_{i}^{k} Cik Calculation
Method 2 : Two dimensional array
Code
def factorial(n):
""" Calculate the factorial :param n: The number to be calculated :return: result """
f = 1
for i in range(1, n+1):
f = f * i
return f
def cik(n, k):
""" Calculate the number of combinations :param n: Count down :param k: Upper number :return: Combination number result """
return int(factorial(n) / (factorial(k) * factorial(n-k)))
n = int(input())
for i in range(1, n+1):
for j in range(1, i+1):
print(cik(i-1, j-1), end=' ')
print()
# Method 2
n = int(input())
num = [[0 for j in range(n)] for i in range(n)]
num[0][0] = 1
print(1)
for i in range(1, n):
num[i][0] = 1
print(1, end=' ')
for j in range(1, i+1):
num[i][j] = num[i-1][j-1] + num[i-1][j]
print(num[i][j], end=' ')
print()
subject 2 Based on practice Special numbers

Their thinking
Judge
Code
def is_ans(n):
a = n % 10
b = (n // 10) % 10
c = (n // 100) % 10
if n == pow(a, 3) + pow(b, 3) + pow(c, 3):
print(n)
for i in range(100, 1000):
is_ans(i)
subject 3 : Based on practice Palindrome number

Their thinking
python section , Positive and negative order are equal
Code
for i in range(1000, 10000):
if i == int(str(i)[::-1]):
print(i)
subject 4 : Based on practice Special palindrome number

Their thinking
python section , Positive and negative order are equal
Run timeout , Because every time the judgment is calculated , Later method After judging that it is not palindrome number , Do not perform subsequent judgments
Code
""" Run timeout , Because every time the judgment is calculated , Later method After judging that it is not palindrome number , Do not perform subsequent judgments n = int(input()) for i in range(10000, 1000000): iStr = str(i) sum = 0 for j in range(len(iStr)): sum += int(iStr[j]) if iStr == iStr[::-1] and sum == n: print(i) """
def is_pal(num):
num = str(num)
if num == num[::-1]:
return True
else:
return False
def sum_num(num):
sum = 0
num = str(num)
for i in range(len(num)):
sum += int(num[i])
return sum
n = int(input())
for num in range(10000, 1000000):
if is_pal(num) and sum_num(num) == n:
print(num)
边栏推荐
- Note: load the configuration file as a byte stream and get the resources in it
- 专升本高数(三)
- Personal PC installation software
- Neo4j--- performance optimization
- 1152_ Makefile learning_ Pattern matching rules
- Global and Chinese market of ULTRACENTRIFUGES 2022-2028: Research Report on technology, participants, trends, market size and share
- unity input system 使用记录(实例版)
- HOOK Native API
- 【笔记】2022.5.28 从网页获取数据并写入数据库
- 【力扣刷题总结】数据库题目按知识点分类总结(持续更新/简单和中等题已完结)
猜你喜欢

The next change direction of database - cloud native database

laravel9本地安裝

X Book 6.89 shield unidbg calling method

How to view Tencent's 2022 school recruitment salary, the total contract of cabbage is 40W?

Use of custom MVC

TiDB 6.0:讓 TSO 更高效丨TiDB Book Rush

Utilisation de foreach en Qt

The broadcast module code runs normally in autojs4.1.1, but an error is reported in pro7.0 (not resolved)

From 2500 a month, no one wants to go to the programming road of the technical director of a large factory | my ten years

【笔记】2022.6.7 数据分析概论
随机推荐
How to view Tencent's 2022 school recruitment salary, the total contract of cabbage is 40W?
Tidb 6.0: rendre les GRT plus efficaces 丨 tidb Book Rush
hudi记录
Ubuntu20.04 PostgreSQL 14 installation configuration record
[qt] qmap usage details
unity input system 使用记录(实例版)
[0x0] 校长留的开放问题作业
Use common fileUpload to upload files
1151_ Makefile learning_ Static matching pattern rules in makefile
The broadcast module code runs normally in autojs4.1.1, but an error is reported in pro7.0 (not resolved)
Hisense A7 ink screen mobile phone cannot be started
Knowledge points of 2022 system integration project management engineer examination: software quality assurance and quality evaluation
[0x0] open questions left by the principal
Simple custom MVC
专升本高数(三)
【筆記】AB測試和方差分析
golang bilibili直播弹幕姬
专升本高数(四)
【力扣刷题总结】数据库题目按知识点分类总结(持续更新/简单和中等题已完结)
Huawei interview question: divide candy