洛谷入门题做题记录

P1161开灯

n = int(input())
a = [0] * 2000001

for i in range(n):
    x, y = map(float, input().split())
    for j in range(1, int(y) + 1):
        idx = int(j * x)
        if a[idx] == 0:
            a[idx] = 1
        else:
            a[idx] = 0

for i in range(1, len(a)):
    if a[i] == 1:
        print(i)
        break

P1152欢乐的跳

s = []
flag = False
for i in map(int,input().split()):
    s.append(i)
del s[0]
b = []
for i in range(1,len(s)):
    b.append(abs(s[i] - s[i-1]))
b.sort()
for j in range(1,len(s)):
    if b[j-1] == j:
        flag = True
    else:
        flag = False
        break
if len(s) == 1:
    print("Not jolly")
else:
    if flag == True:
        print("Jolly")
    else:
        print("Not jolly")

P1151子数整数

flag = False
k = int(input())
for number in range(10000, 30001):
    a = []
    # 使用 for 循环遍历字符串中的每个字符
    number_str = str(number)
    for char in number_str:
        digit = int(char)  # 将字符转换为整数
        a.append(digit)
    sub_1 = a[0] * 100 + a[1] * 10 + a[2]
    sub_2 = a[1] * 100 + a[2] * 10 + a[3]
    sub_3 = a[2] * 100 + a[3] * 10 + a[4]
    if sub_1 % k == 0 and sub_2 % k == 0 and sub_3 % k == 0:
        print(number)
        flag = True
if flag == False:
    print("No")

P1150Peter的烟

a,b = map(int, input().split())
n = 0
while a>=b:
    a = a -b
    n += 1
    a += 1
print(n*b+a)

P1089津津的储存计划

sum = 0
deposit =0
surplus = 0
flag = True
for i in range(1,13):
    budget = int(input())
    surplus += 300 - budget
    if surplus < 0:
        flag = False
        break
    deposit += surplus//100
    surplus %= 100
if  flag == True:
    print(deposit*120+surplus)
else:
    print(-i)

P1085不高兴的津津

max_unhappy = 0
max_unhappy_day = 0

for day in range(1, 8):
    school_hours, mom_hours = map(int, input().split())
    total_hours = school_hours + mom_hours

    if total_hours > 8 and total_hours - 8 > max_unhappy:
        max_unhappy = total_hours - 8
        max_unhappy_day = day

print(max_unhappy_day)

P1075质因数分解

这题很简单,但要注意审题,题目已经说了是两个质数的乘积,就不要像我一样第一遍还写了个判断质数的方法了

n = int(input())
for i in range(2,n//2+1):
    if n % i == 0:
        print(n//i)
        break

P1047校门外的树

L, n = map(int, input().split())
a = list(range(L + 1))

for _ in range(n):
    p, q = map(int, input().split())
    for i in range(p, q + 1):
        a[i] = -1

ans = sum(1 for i in range(L + 1) if a[i] >= 0)
print(ans)

P1046陶陶摘苹果

apple=list(map(int,input().split()))
height=int(input())
n=0
for i in range(0,9):
    if apple[i]<=height:
        n+=1
print(n)

P1035级数求和

s=float(input())
sum=0
active=True
i=0
while active:
    i+=1
    sum+=1.0/i
    if sum>s:
        print(i)
        active=False
    
    

 P1179数字统计

a,b = map(int,input().split())
count = 0
for number in range(a,b+1):
    c = []
    number_str = str(number)
    c = [int(char) for char in number_str if char.isdigit()]
    for j in c:
        if j == 2:
            count +=1
print(count)

 P1200Your Ride Is Here

def name_to_number(name):
    total = 1
    for letter in name:
        # 将字母转换为数字,A对应1,Z对应26
        letter_number = ord(letter) - ord('A') + 1
        total *= letter_number
    return total

a = input()
b = input()
c = name_to_number(a)
d = name_to_number(b)
if c%47 == d%47:
    print("GO")
else:
    print("STAY")

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值