ZOJ Problem Set
第32页
Sequence in the Pocket
思维题
给定一个序列,每次可以将一个元素移到最前面,问你最少使用多少次,将元素排成上升序列。
解题思路:其实可以先创建一个新数组进行排序,排序后的数组和原先数组从后往前有多少个不一样的元素就是移动的次数
T = int(input())
for _ in range(T):
n = int(input())
arr = list(map(int, input().split()))
sorted_arr = sorted(arr)
j = len(sorted_arr) - 1
for i in range(len(arr) - 1, -1, -1):
if arr[i] == sorted_arr[j]:
j = j - 1
print(j + 1)
Abbreviation
给出一个字符串 要你将里面的a e i y o u删掉并输出 注意!首位不需要删掉
t = int(input())
vowel = {'a', 'e', 'i', 'y', 'o', 'u'}
for _ in range(t):
word = input()
new=""
for i in range(len(word)):
if i==0 or word[i] not in vowel:
new = new +word[i]
print(new)
Lucky 7 in the Pocket
给出一个数 n,输出一个大于等于 n 的数 m,要求 m 能被 7 整除但不能被 4 整除
T = int(input())
for _ in range(T):
n = int(input())
m = n
while True:
if m % 7 == 0 and m % 4 != 0:
break
m = m + 1
print(m)
Calandar
有一个神奇的星球,在那里,一年有12个月,每月都有30天。并且在那个星球上一周只有五天。给你今天的日期和星期,问你一个目标日期是星期几。
只要求出两个日的关系,再输出对应的星期即可
day =["Monday", "Tuesday", "Wednesday", "Thursday" , "Friday"]
T = int(input())
for _ in range(T):
y1, m1, d1, today_day = input().split()
y1, m1, d1 = int(y1), int(m1), int(d1)
y2, m2, d2 = map(int, input().split())
total_days = (y2 - y1) * 12 * 30 + (m2 - m1) * 30 + (d2 - d1)
for i in range(len(day)):
if day[i]==today_day:
today_index = i
if total_days>=0:
target_index = (today_index + total_days) % 5
else:
total_days = abs(total_days)%5
target_index = (today_index+5 -total_days)%5
print(day[target_index])
Stones in the Bucket
这题的要求是让你把每块石碓平均一下,每次只能移动一块石头或者直接丢掉一块石头,问你最少的次数
其实你只要把石头总数求和再平均一下,对于超过平均数的石头块减一下就是答案
T = int(input())
for _ in range(T):
n = int(input())
stones = list(map(int, input().split()))
total = sum(stones)
average = total//n
cnt = 0
for i in range(n):
if stones[i]>average:
cnt = cnt+ stones[i] -average
print(cnt)
League of Legends
蓝方的血量是红方减的;红方的血量是蓝方减的。蓝方先手,减的是红方血量。
因此除了统计红方和蓝方的总血量,要注意蓝方先手,红方先被扣血。当蓝方血量大于等于红方血量,都是蓝方赢,否则相反。
blue_hp = list(map(int, input().split()))
red_hp = list(map(int, input().split()))
total_blue = sum(blue_hp)
total_red = sum(red_hp)
if total_blue >= total_red:
print("Blue")
else:
print("Red")
第31页
PPAP
让两个字符串相加,第一个字符串首字符变大写,第二个首字符删除
T = int(input())
for _ in range(T):
a, b = input().split()
s1 = b + a
s2 = s1[0].upper() + s1[1:]
print(s2)
Peak
让你在字符串中找一个山峰,只需要从左最大山峰和从右最大的山峰下标相等就可以输出Yes否则输出No
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int,input().split(" ")))
l=0
r=n-1
for i in range(n-1):
if a[i]>= a[i+1]:
l=i
break
for i in range(n-1, 0,-1):
if a[i-1]<=a[i]:
r=i
break
if l==r :
print("Yes")
else:
print("No")
King of Karaoke
有两个序列D和S,D加上K之后和S有多少个数是相同的
T = int(input())
for _ in range(T):
n = int(input())
d = list(map(int, input().split()))
s = list(map(int, input().split()))
diff = {}
res = 0
for i in range(n):
a = d[i]-s[i]
if a in diff:
diff[a]=diff[a]+1
else:
diff[a] = 1
print(max(diff.values()))
Lucky 7
一个序列,只要有一个元素+b能被7整除就是Yes,如果全部都不能整除就是No
T = int(input())
for _ in range(T):
n, b = map(int, input().split())
a = list(map(int, input().split()))
f =0
for i in range(n):
if (a[i]+b)%7==0:
f=1
break
if f==1:
print("Yes")
else:
print("No")
Peer Review
有n个同学,每个学生必须分别对其他(n-1)个学生打分,那么自然,为了让自己分数最高,给其他人都打0分的,所以所有人的分数都是0
同学们,冤冤相报何时了!
T = int(input())
for _ in range(T):
n = int(input())
for i in range(n):
if i!=0:
print(" ",end='')
print("0",end='')
print()
Live Love
最大连击数就是所有的PERFECT连在一起
最小连击数可以考虑n−m个 “NON-PERFECT” 排列好,它们之间以及两端会形成 n−m+1个间隔。之后我们m个PERFECT尽量平均地放入这些间隔中,即m/(n-m+1),当然最后要考虑向上取整的问题。
import math
T = int(input())
for _ in range(T):
n,m = map(int,input().split())
r = m/(n-m+1)
r = math.ceil(r)
print(m,r)
第30页
27,36,47,58,59,92
Programming Ability Test
总成绩大于等于80则输出Yes,否则输出No
T = int(input())
for _ in range(T):
ScoreA, ScoreB, ScoreC, ScoreD = map(int, input().split())
total = ScoreA + ScoreB + ScoreC + ScoreD
if total >= 80:
print("Yes")
else:
print("No")
Apples and Ideas
知识可以共享,但苹果不是!所以交换后,苹果总数没有发生变化,但知识却是求和
T = int(input())
for _ in range(T):
A, B, C, D = map(int, input().split())
alice_apples = C
alice_ideas = B + D
bob_apples = A
bob_ideas = B + D
print(alice_apples, alice_ideas)
print(bob_apples, bob_ideas)
Very Happy Great BG
对朋友总数求和即可
T = int(input())
for _ in range(T):
N = int(input())
friends = list(map(int, input().split()))
total = N + sum(friends)
print(total)
Cooking Competition
两个人比赛厨艺,有n个评委,每个评委可能给出4种评价,1表示A加1分,B不加分,2表示A不加分,B加1分,3表示两人各加1分,4表示两人各扣1分,问最后谁赢了比赛还是平局
T = int(input())
for _ in range(T):
n = int(input())
feedbacks = list(map(int, input().split()))
kobayashi_score = 0
tohru_score = 0
for feedback in feedbacks:
if feedback == 1:
kobayashi_score += 1
elif feedback == 2:
tohru_score += 1
elif feedback == 3:
kobayashi_score += 1
tohru_score += 1
else:
kobayashi_score -= 1
tohru_score -= 1
if kobayashi_score > tohru_score:
print("Kobayashi")
elif tohru_score > kobayashi_score:
print("Tohru")
else:
print("Draw")
Problem Preparation
题目难度排序后判断即可
T = int(input())
for _ in range(T):
n = int(input())
s = list(map(int, input().split()))
f = True
if n<10 or n>13:
print("No")
continue
s.sort()
if s[0]!=1 or s[1]!=1:
f = False
for i in range(len(s) - 2):
if abs(s[i + 1] - s[i]) > 2:
f = False
if f:
print("Yes")
else:
print("No")
One-Dimensional Maze
思维题,解题的关键在于判断从起始位置到开头或到结尾的修改字符数哪个更少。具体步骤如下:
1.判断起始位置:如果起始位置在开头或结尾,可以直接到达目标位置,无需修改字符。
2.计算修改字符数:
从起始位置到开头的修改字符数:遍历从起始位置到开头的所有字符,将'R'改为'L'。
从起始位置到结尾的修改字符数:遍历从起始位置到结尾的所有字符,将'L'改为'R'。
3.选择最小修改次数:比较上述两种情况的修改次数,选择较小的那个作为答案。
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
ch = input()
if m == 1 or m == len(ch):
print(0)
continue
ans1 = 0
ans2 = 0
for i in range(1, m - 1):
if ch[i] == 'R':
ans1 += 1
for i in range(m, len(ch) - 1):
if ch[i] == 'L':
ans2 += 1
if ch[m - 1] == 'L':
print(min(ans1, ans2 + 1))
else:
print(min(ans1 + 1, ans2))
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)