当前位置:网站首页>[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)
边栏推荐
- Ubuntu20.04 PostgreSQL 14 installation configuration record
- [QT] QMap使用详解
- [frequently asked questions] modularization of browser environment and node environment
- Hudi record
- Principle of device driver
- 图的邻接矩阵存储 C语言实现BFS
- The next change direction of database - cloud native database
- QT中foreach的使用
- 【作业】2022.5.23 MySQL入门
- Use of foreach in QT
猜你喜欢

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

数据库的下一个变革方向——云原生数据库

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

Linked list: insert a node in the head

QT中foreach的使用

1151_ Makefile learning_ Static matching pattern rules in makefile

laravel9本地安装

SDS understanding in redis

Hisense A7 ink screen mobile phone cannot be started

LitJson解析 生成json文件 读取json文件中的字典
随机推荐
The broadcast module code runs normally in autojs4.1.1, but an error is reported in pro7.0 (not resolved)
AppData文件夹下Local,Locallow和Roaming
Dripping backward (II)
【筆記】AB測試和方差分析
From 2500 a month, no one wants to go to the programming road of the technical director of a large factory | my ten years
Use of foreach in QT
X Book 6.89 shield unidbg calling method
*Write a program to initialize a string object with a vector < char> container*/
[frequently asked questions] modularization of browser environment and node environment
共124篇!墨天轮“高可用架构”干货文档分享(含Oracle、MySQL、PG)
C#【高级篇】 C# 匿名方法【待补充Lambda表达式。。。】
C # [advanced part] C # multithreading
Feign pit
What are the defaults for Binding. Mode=Default for WPF controls?
Are you a "social bull" or a "social terrorist" in the interview?
SDS understanding in redis
王爽-汇编语言 万字学习总结
OP diode limit swing
51 single chip microcomputer indoor environment monitoring system, mq-2 smoke sensor and DHT11 temperature and humidity sensor, schematic diagram, C programming and simulation
Gulang bilibilibili Live Screen Jackie