Gửi bài giải
Điểm:
100,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
512M
Input:
stdin
Output:
stdout
Dạng bài
Ngôn ngữ cho phép
Python, Scratch
Bình luận
EZ NHƯNG SRATCH :)
def isbeautifulnumber(num): """ Check if a number is beautiful. A number is beautiful if it consists only of digits 6 and 8 or starts with 6 followed by digits that may include 8. """ str_num = str(num)
def findbeautifulposition(N): """ Find the position of a beautiful number in the ordered list of beautiful numbers. """ beautiful_numbers = []
Example usage
if name == "main": N = int(input("Enter a natural number N: ")) result = findbeautifulposition(N) print(result)
mình đươc 3/5 2 cái TLE
helps me,plese
//code ne dung full n = input() ind = int(len(n) * (len(n) + 1) / 2 - 1) + (n.count('8') + 1)
if '8' not in n and '6' not in n: print('NO') else: x = -1 y = -1 if '8' in n: x = n.index('8') if '6' in n: y = n.index('6')
kíu toi với
số 666 mà là số đẹp thì chịu rồi =)
print("cho cách làm")
code nè s = str(n) length = len(s) position = 0
Đếm các số đẹp có ít chữ số hơn
for i in range(1, length): position += countbeautifulnumberswithlength(i)
Đếm các số đẹp có cùng số chữ số
for i in range(length): if s[i] == '6': continue elif s[i] == '8': position += 2 ** (length - i - 1)
position += 1 # Chuyển từ chỉ số 0-based sang 1-based return position
de ma,nhng tui chi dc 80/100:)))
Bài này chỉ có 2 số , ý nghĩa của bài này là mạnh luôn đúng sau yếu để phòng thủ một cách thông minh ( mình nghĩ vậy :) )
from collections import deque def generatenumbers(limit): result = [] queue = deque(["6", "8"]) while queue: s = queue.popleft() if "86" not in s: result.append(s) if len(s) < limit: queue.append(s + "6") queue.append(s + "8") return result A=generatenumbers(16) N=input() for i in range(len(N)-1): if N[i]>N[i+1] or (N[i]!='6' and N[i]!='8'): print('NO') break else: for j in range(len(A)): if A[j]==N: print(j+1) break 5/5 ạ
https://scratch.mit.edu/projects/1169752772 Code Scratch của mình đây các bạn!Mình được 100% số điểm với code của mình.
code AC NÈ (100%) def is_beautiful(number): s = str(number) if any(ch not in '68' for ch in s): return False if '86' in s: return False return True
def generatebeautifulnumbers(maxlength=15): from itertools import product beautifulnumbers = [] for length in range(1, maxlength + 1): for digits in product('68', repeat=length): num = ''.join(digits) if isbeautiful(num): beautifulnumbers.append(int(num)) beautifulnumbers.sort() return beautiful_numbers
def findposition(N): if not isbeautiful(N): return "NO" beautifulnumbers = generatebeautifulnumbers(len(str(N))) position = 1 for num in beautifulnumbers: if num == N: return position position += 1 return "NO"
Input
N = int(input())
Output
print(find_position(N))
tối ưu cho bạn: n = input() if any(c not in '68' for c in n) or '86' in n: print("NO") else: l = len(n) s8 = n.count('8') res = ((l + 2) * (l - 1)) // 2 + (s8 + 1) print(res)
công thức đc full test 5/5: ((2 + (độ dài cuả n)) x ((độ dài cuả n)-1)) / 2 + (số lượng số 8 trong n + 1)
def isbeautiful(n): #a beautiful numner is a number include only 6 and 8 and 6 stand before 8 adn no 8 stand before 6 #check if include non 6 and 8 for i in str(n): if i != '6' and i != '8': return False #check if 8 stand before 6 for i in range(len(str(n))): if str(n)[i] == '6': for j in range(i): if str(n)[j] == '8': return False return True def nthbeautiful(n): # if not isbeautiful(n): # return False # 6 is the 1st beautiful number # 8 is the 2nd beautiful number # 66 is the 3rd beautiful number # 68 is the 4th beautiful number # 88 is the 5th beautiful number # 666 is the 6th beautiful number # guess the nth beautiful number listnum = [] for num6 in range(16): for num8 in range(16): if 0<num6 + num8 <=16 : listnum.append(int('6' * num6 + '8' * num8)) listnum.sort() # get the index of n in the listnum return listnum.index(n) + 1 if n in listnum else False def main(): n = int(input()) if isbeautiful(n): print(nthbeautiful(n)) else: print("NO") # print (nthbeautiful(n)) if name == "main": main()
Heading ##o
Đầu tiên cứ đếm SLS 8 rồi làm theo công thức:(độ dài của N+1)x độ dài của N:2.Sau đó cộng với SLS 8 là ra vị trí.Làm trên scratch cũng được max điểm nè.
ko cần lập danh sách chỉ cần kiểm tra số đẹp. Bắt đầu từ 1, tăng dần lên n, cứ mỗi số lại kiểm tra 1 lần nếu đúng thì tăng kết quả lên 1, nếu ko thì tiếp tục tăng.
Cho mình hỏi làm sao để làm được danh sách số đẹp vậy?
N=input() KQ=[] for x in range(0,len(N)): tam='' for y in range(0,x+1): tam=tam+'6' KQ.append(tam) for y in range(0,x+1): tam=tam.replace('6','8',1) tam1=tam[: :-1] KQ.append(tam1) if N in KQ: print(KQ.index(N)+1) else: print('NO')
n = input() ind = int(len(n) * (len(n) + 1) / 2 - 1) + (n.count('8') + 1)
if '8' not in n and '6' not in n: print('NO') else: if '8' in n: x = n.index('8') if '6' in n: y = n.index('6') else: y = 0 if x < y: print('NO') else: if n[:x].count('6') == len(n[:x]): print(ind) else: print('NO') else: if n.count('6') == len(n): print(ind) else: print('NO')
ai đó có thể gửi file code của scratch để tôi học đc ko ạ?
n=input() ind=int(len(n)*(len(n)+1)/2-1)+(n.count('8')+1) if not '8' in n and not '6' in n: print('NO') else: if '8' in n: x=n.index('8') if '6' in n: y=n.index('6') else: y=0 if x < y : print('NO') else: if (n[0:x]).count('6')==len(n[0:x]): print(ind) else: print('NO') else: if n.count('6')==len(n): print(ind) else: print(ind)
tui đc có 80 điểm😞😞😞😞😞😞
ko khó lắm ak mọi người ai cần code py ko mình có nek 100% ac
cho tôi xin với
easy 2:00 la xong
nhưng chỉ được 4/5 thôi
https://scratch.mit.edu/projects/1043235043/editor
Bạn chưa chia sẻ bài của mình à
Sao lại không thấy
editor sao vô cha
404 Không tìm thấy
không có gì, mik tìm thấy rồi,cảm ơn bạn nhé!
thiệt ko???
sao mình ko tìm được vậy bạn,toàn lỗi hệ thống ko à
TUI CÓ LINK SCRATCH NÈ
có ai biết code của scratch không? chỉ mik với
cứu
Đây code nè. dù bị sai nhưng có đỡ hơn không :)) def isbeautifulnumber(n): s = str(n) if any(d not in '68' for d in s): return False if '86' in s: return False return True
def countbeautifulnumberswithlength(l): return 2 ** l
def beautifulnumberposition(n): if not isbeautifulnumber(n): return "NO"
Đọc đầu vào và in ra kết quả
N = int(input("Nhập một số tự nhiên N: ")) print(beautifulnumberposition(N))
chả đc tòn 80 luôn á
Chào mọi người, em muốn hỏi là khi mình qua được bài đó rồi thì mình không thể xem được bài giải của người khác mặc dù mình đã accept bài đó rồi? Chỉ có thể xem code của mình? Em xin cảm ơn mọi người giải đáp thắc mắc
Đúng thế
Hinh nhu la the that
đúng thiệt
Bình luận này đã bị ẩn vì có quá nhiều phản ứng tiêu cực. Nhấn để xem.
HURA
Bình luận này đã bị ẩn vì có quá nhiều phản ứng tiêu cực. Nhấn để xem.
Bình luận này đã bị ẩn vì có quá nhiều phản ứng tiêu cực. Nhấn để xem.