当前位置:网站首页>[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)
边栏推荐
- 第2章 控制结构和函数(编程题)
- Practical debugging skills
- Tidb 6.0: rendre les GRT plus efficaces 丨 tidb Book Rush
- 【笔记】2022.6.7 数据分析概论
- Auto.js学习笔记15:autojs的UI界面基础篇2
- [Note] ab Test and Variance Analysis
- [frequently asked questions] modularization of browser environment and node environment
- Utilisation de foreach en Qt
- Ubuntu20.04 PostgreSQL 14 installation configuration record
- unity input system 使用记录(实例版)
猜你喜欢

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

X书6.97版本shield-unidbg调用方式

December2020 - true questions and analysis of C language (Level 2) in the youth level examination of the Electronic Society

Simple custom MVC

Use common fileUpload to upload files

The 5-year Android development interview took 20 days to join Alibaba

QT中foreach的使用

How do college students make money by programming| My way to make money in College

Mysql性能优化(6):读写分离

MySQL performance optimization (6): read write separation
随机推荐
TiDB 6.0:让 TSO 更高效丨TiDB Book Rush
Auto. JS learning notes 15:ui interface basics of autojs Chapter 2
1150_ Makefile learning_ Duplicate name target processing in makefile
JS cross reference
Litjson parses the generated JSON file and reads the dictionary in the JSON file
[FAQ] page cross domain and interface Cross Domain
laravel9本地安装
Link garbled escape character
Realization of BFS in C language by storing adjacency matrix of graph
Product thinking - is the future of UAV express worth looking forward to?
Principle of device driver
JS conversion of letters and numbers
Huawei interview question: tall and short people queue up
Compile a DLL without import table
A GPU approach to particle physics
Use common fileUpload to upload files
An article to get you started VIM
X Book 6.97 shield unidbg calling method
11: I came out at 11:04 after the interview. What I asked was really too
Global and Chinese market for sensor screwdrivers 2022-2028: Research Report on technology, participants, trends, market size and share