当前位置:网站首页>Blue Bridge Cup - palindromes and special palindromes
Blue Bridge Cup - palindromes and special palindromes
2022-04-21 07:39:00 【Qian & Shou】
Topic 1
Subject requirements
Resource constraints
The time limit :1.0s Memory limit :512.0MB
Problem description
1221 It's a very special number , It's the same thing to read from the left as it is to read from the right , Programming for all such four decimal numbers .
Output format
According to the order from small to large output to meet the conditions of four decimal numbers .
Solution 1 :
for i in range(1000,10000):
if str(i) == str(i)[::-1]:
print(i)
Solution 2 :
Through the symmetry of palindrome number , We can simplify the original four digits to two digits , In order to reduce CPU And memory usage
l = []
for i in range(10,100):
l.append(str(i) + str(i)[::-1])
for i in sorted(map(int,l)):
print(i)
Topic two
Subject requirements
Resource constraints
The time limit :1.0s Memory limit :512.0MB
Problem description
123321 It's a very special number , It's the same thing to read from the left as it is to read from the right .
Enter a positive integer n, Programming for all such five and six decimal numbers , The sum of your numbers equals n .
Input format
The input line , Contains a positive integer n.
Output format
Output the integers satisfying the conditions in the order of small to large , Each integer takes up one line .
The sample input
52
Sample output
899998
989989
998899
Data size and engagement
1<=n<=54.
Solution 1 :
Ideas : First, traverse all five and six digits , Determine whether it conforms to the basic characteristics of palindrome number through slice inversion list . If it conforms to , Judge whether the numbers and answers of this question meet the special requirements , Output if yes .
n = int(input())
for i in range(10000,1000000):
a = str(i)
if a == a[::-1]:
if n == sum(int(j) for j in a):
print(a)
Solution 2 :
Solution 2 of the same principle , That is, through the symmetry of palindromes , Simplify the original five or six digits to three digits , Similarly, the slice inversion method is used to judge whether the five digit and six digit meet the conditions .
n = int(input())
l = []
for i in range(100,1000):
if sum(map(int,str(i)+(str(i)[:2])[::-1])) == n: # Five figures
l.append(str(i)+(str(i)[:2])[::-1])
if sum(map(int,str(i)+str(i)[::-1])) == n: # Six figures
l.append(str(i)+str(i)[::-1])
for i in sorted(map(int,l)): # Output the integers satisfying the conditions in the order of small to large
print(i)
By running the code of solution one and solution two , Discovery solution I CPU The usage is 390ms, And solution two has only 31ms.
版权声明
本文为[Qian & Shou]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210624476191.html
边栏推荐
猜你喜欢
随机推荐
华天OA漏洞复现手册
解决中文乱码问题
宏晶微MS9288、模拟RGB(VGA)转HDMI,HDMI发射器,音频解码器,内置MCU
利用WireShark将pcap数据流还原图片文件
PIM-DM
Basic concepts of IP Multicast
Sorting method (3) = > quick sort and merge sort
Convergencewarning: linear failed to converge, increase the number of iterations
使用百度地图POI爬取需要的数据
短信逻辑漏洞
Steps of connecting hbuilderx to nocturnal simulator
Ruiyuan power chip, ry3715, ry3750 replacement: silijie sy7208, sy7152, Xinpeng micro ap2008 Core source mp1542, mp3213. Input voltage from 2.5V to 5.5V
CS5518,MIPI转双路LVDS,替换:国腾的GM8775,东芝TC358775,双路LVDS,国产完美替换,DSI 转双通道 LVDS,,LVDS 时钟频率最高154MHz,1920 x1200
Macro crystal micro ms9288, analog RGB (VGA) to HDMI, HDMI transmitter, audio decoder, built-in MCU
Nmap扫描和Scapy项目
Cs5518, Mipi to dual LVDS, replacement: gm8775 of Guoteng, tc358775 of Toshiba, dual LVDS, domestic perfect replacement, DSI to dual channel LVDS, LVDS clock frequency up to 154mhz, 1920 x1200
BGP neighbor
龙讯系列视频转换,LT9211、LT8918,功能:lvds转BT656,lvds转mipi(CSI\DSI)RGB转MIPI(DSI\CSI) BT656\601\1120转HDMI1.4\DVI
Jfinal hutool tool excel util ziputil realizes exporting excel and compressing files
2020-12-24









