绍兴市大学生程序设计竞赛
前言
现在暂时在台州学院oj上做题目
网址链接https://www.tzcoder.cn/acmhome/problemList.do?method=show
3275
C = int(input())
while C>0:
C = C-1
L,M,N= map(int, input().split())
print(M*N+L)
3277
t = int(input())
while t>0:
t = t-1
n = int(input())
cnt = 0
for i in range(n):
s = input()
if s=="Exchange":
cnt = cnt+1
else:
if(cnt%2==0): print("YES")
else : print("NO")
3278
# 预先计算并存储“快乐数”
# import time
happy_array = [False] * 5000001
happy_array[1] = True
res = [0] * 5000001
for i in range(505):
num_set = set()
temp=i
while True:
if temp in num_set:
break
num_set.add(temp)
sum = 0
for digit in str(temp):
sum += int(digit) ** 2
# 如果已经是快乐数了,就不用算了
if happy_array[sum] == True:
temp=1
break
temp =sum
if temp==1:
happy_array[i]=True
def findall(n):
sum = 0
for digit in str(n):
sum += int(digit) ** 2
if happy_array[sum] == True:
res[i] = res[i - 1] + 1
else:
res[i] = res[i - 1]
res[1]=1
for i in range(2,5000001):
findall(i)
t = int(input())
while t>0:
t = t-1
n = int(input())
print(res[n])
3280
切的时候按照2的倍数切,比如1,2,4,8,这样子就能表示1-\(2^{n+1}\)-1的范围,n为切的次数
t = int(input())
while t>0:
t = t-1
n = int(input())
if n==1:
print("0")
continue
i=0
while True:
if 2**i-1>=n:
print(i-1)
break
i=i+1
3752
while True:
n = int(input())
if n==0: break
num_str = str(n)
new_num= num_str[-1] + num_str[:-1]
if int(new_num)%n==0: print("Yes")
else:print("No")
3753
while True:
try:
num = int(input()) # 获取输入的无符号整数
binary_num = format(num, 'b').zfill(32) # 将整数转换为32位二进制字符串
new_binary_num = binary_num[16:] + binary_num[:16] # 交换前后16位
result = int(new_binary_num, 2) # 将新的二进制字符串转换回整数
print(result)
except EOFError:
break
3756
import math
def f(n):
res = 1
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
if (i != int(n / i)):
res = res * i % 10007 * int(n / i) % 10007
else:
res = res * i % 10007
print(res)
t = int(input())
while t>0:
t = t-1
n = int(input())
f(n)
3758
while True:
try:
s= input()
res=0
for i in range(len(s)):
if s[i]>='a' and s[i]<='z':
res =res+ ord(s[i])-ord('a')+1
if s[i]>='A' and s[i]<='Z':
res = res + ord(s[i])-ord('A') + 1
print(res)
except EOFError:
break
3760
T = int(input()) # 读取测试用例数量
for _ in range(T):
n = int(input()) # 读取房子的数量
houses = []
# 读取每个房子的相关信息,并计算偏好度
for _ in range(n):
a, b, c, d = map(int, input().split())
sum = (1000-a)+(b-20)+(c-40)
if a > 1000 or b < 20 or c < 40:
continue
houses.append((sum, d)) # 存储偏好度和房屋编号
# 找到最大的偏好度
max_pre =-1
for i in range(len(houses)):
if houses[i][0]>max_pre:
max_pre=houses[i][0]
# 挑选出所有的房子
result=[]
for i in range(len(houses)):
if houses[i][0]==max_pre:
result.append(houses[i][1])
result.sort()
#输出所有值
for i in range(len(result)):
if i!=0: print(" ",end='')
print(result[i],end='')
print()
6752
找规律,只要A一步就能到达B周围的一格先手就必胜
下图绿色区域就为A能达到B周围的一格的区域(即为Suzukaze获胜的区域)
t = int(input())
while t>0:
t = t-1
xa, xb, ya, yb = map(int, input().split())
sum = abs(xa - ya) + abs(xb - yb)
if xa == ya or xb == yb:
if sum >= 3:
print("Yukikaze")
else:
print("Suzukaze")
else:
if sum >= 4:
print("Yukikaze")
else:
6754
t = int(input())
while t>0:
t = t-1
a,b,c= map(int, input().split())
if a+b<c: print("small")
elif a+b==c: print("equal")
else: print("big")
7960
n, x = map(int, input().split())
nums = list(map(int, input().split()))
nums.sort()
for i in range(n):
if i+1>=n:
print(n)
break
if nums[i]+nums[i+1]>x:
print(i+1)
break
8380
n = int(input())
nums = list(map(int, input().split()))
max_val = max(nums)
min_val = min(nums)
for i in range(len(nums)):
if abs(nums[i]-max_val)>abs(nums[i]-min_val):
print(abs(nums[i]-max_val))
else:
print(abs(nums[i] - min_val))
8382
print("2023.11.19")
8385
import math
def find_set_faster(n):
if n < 10:
return None
max_z = int(math.log(n, 5))
max_y = int(math.log(n, 3))
max_x = int(math.log(n, 2))
for z in range(1,max_z+1):
for y in range(1,max_y+1):
for x in range(1,max_x+1):
if 2 ** x+3 ** y+5 ** z == n:
return x, y, z
return None
while True:
try:
n = int(input())
result = find_set_faster(n)
if result:
print(result[0],result[1],result[2])
else:
print(-1)
except EOFError:
break
8388
#dp[i]代表使用i个魔法点之后能达到最大的m个任务
dp = [float('inf')] * (55)
dp[0] = 1
dp[1] = 2
i=2
while True:
dp[i]= max(dp[i-1]*2,dp[i-2]*5)
if dp[i]>10 ** 18: break
i=i+1
def f(n):
i = 0
while True:
if dp[i] >= n:
print(i)
return
i = i + 1
t= int(input())
while t>0:
t=t-1
n = int(input())
f(n)
非比赛题目
1011
cnt = 0
while True:
n = int(input())
if n == 0: # 结束条件
break
heights = list(map(int, input().split()))
total_bricks = sum(heights) # 总砖块数
average_bricks = total_bricks // n # 每个堆栈应该有的高度
# 计算需要移动的砖块数
moves = 0
for height in heights:
if height > average_bricks:
moves = moves+ (height - average_bricks)
cnt = cnt + 1
print(f"Set #{cnt}")
print(f"The minimum number of moves is {moves}.")
print()
1012
def find(codes):
for i in range(len(codes)):
for j in range(len(codes)):
if i==j: continue
# 如果第一个编码是第二个编码的前缀,则不是立即可解码
if codes[j].startswith(codes[i]): return False
return True
cnt = 0
while True:
try:
cnt = cnt+1
codes = []
while True:
code = input()
if code == '9':
break
codes.append(code)
# 判断当前组的编码是否是立即可解码的
if find(codes):
print(f"Set {cnt} is immediately decodable")
else:
print(f"Set {cnt} is not immediately decodable")
except EOFError:
break
1021
t = int(input())
for _ in range(t):
data = list(map(int, input().split()))
K = data[0] # 电源插座的数量
data = data[1:] # 每个电源插座提供的插口数量
result = sum(data)-K+1
print(result)
1085
import math
lines = []
pre=[]
for i in range(16):
data = list(map(int, input().split()))
pre.append(data)
while True:
data = list(map(int, input().split()))
if data == [-1, -1, -1]:
break
min_distance = float('inf')
nearest_color = None
for i in range(16):
r1, g1, b1 = data
r2, g2, b2 = pre[i]
distance = math.sqrt((r1 - r2) ** 2 + (g1 - g2) ** 2 + (b1 - b2) ** 2)
if distance < min_distance:
min_distance = distance
nearest_color = pre[i]
print(f"({data[0]},{data[1]},{data[2]}) maps to ({nearest_color[0]},{nearest_color[1]},{nearest_color[2]})")
1130
n = int(input())
for _ in range(n):
num1, num2 = input().split()
num1 = int(num1[::-1])
num2 = int(num2[::-1])
sum_num = int(str(num1 + num2)[::-1])
print(sum_num)
1143
while True:
try:
s, t = input().split()
i, j = 0, 0
while i < len(s) and j < len(t):
if s[i] == t[j]:
i += 1
j += 1
if i == len(s):
print('Yes')
else:
print('No')
except EOFError:
break
1161
while True:
try:
sum=0
n = int(input())
for i in range(n):
sum= sum+i+1
print(sum)
print()
except EOFError:
break
1182
while True:
data = list(map(int, input().split()))
if data[0] ==0:break
sum =0
for i in range(1,len(data)):
sum = sum+data[i]
print(sum)
1184
while True:
data = list(map(int, input().split()))
if data[0] == 0:
break
time =0
cnt = 0
for i in range(1,len(data)):
if cnt < data[i]:
time = time +(data[i]-cnt)*6
if cnt >data[i]:
time = time + (cnt-data[i])*4
cnt = data[i]
time =time+5
print(time)
1304
while True:
m, n = map(int, input().split())
if m == -1 and n == -1:
break
items = []
for _ in range(n):
j, f = map(int, input().split())
items.append((j, f))
items.sort(key=lambda x: x[0] / x[1], reverse=True)
res = 0
for j, f in items:
if m == 0:
break
if f <= m:
res += j
m -= f
else:
res += j * (m / f)
m = 0
print(f"{res:.3f}")
1305
while True:
n = int(input())
if n == 0:
break
while n >= 10:
n = str(n)
new_num = 0
for digit in n:
new_num += int(digit)
n = new_num
print(n)
1309
def cycle_length(n):
length = 1
while n != 1:
if n % 2 == 0:
n = n // 2
else:
n = 3 * n + 1
length += 1
return length
while True:
try:
i, j = map(int, input().split())
res =0
for num in range(i, j + 1):
length = cycle_length(num)
if res<length:
res = length
print(i,j,res)
except EOFError:
break
1312
while True:
num_list = list(map(int, input().split()))
n,u,d = num_list
if n == 0:
break
height = 0
time = 0
while True:
# 先向上爬
height += u
time += 1
if height >= n:
break
# 然后下滑
height -= d
time += 1
print(time)
1402
while True:
try:
num = int(input())
res=""
while num:
res = str(num%2)+res
num = num//2
print(res)
except EOFError:
break
1403
while True:
try:
# 获取输入的宽度和高度
width, height = map(int, input().split())
# 绘制矩形的上边框
print('+' + '-' * width + '+')
for _ in range(height):
# 绘制矩形的中间部分
print('|' + ' ' * width + '|')
# 绘制矩形的下边框
print('+' + '-' * width + '+')
print()
except EOFError:
break
1404
while True:
try:
n = int(input())
lamp = [0] * n
for i in range(1, n + 1):
for j in range(i - 1, n, i):
lamp[j] = 1 - lamp[j]
print(lamp[n - 1])
except EOFError:
break
1405
t = int(input())
for _ in range(t):
letter, num = input().split()
num = int(num)
if 'A' <= letter <= 'Z':
value = ord(letter) - ord('A')+1
else:
value = - (ord(letter) - ord('a')+1)
print(num + value)
1406
while True:
try:
num1, num2 = input().split()
num1 = int(num1, 16)
num2 = int(num2, 16)
sum_num = num1+num2
print(format(sum_num,'X'))
except EOFError:
break