首页 > 试题广场 >

田忌赛马

[编程题]田忌赛马
  • 热度指数:23454 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}田忌与齐威王正在赛马,比赛一共三局,三局两胜,当一方马匹速度严格大于另一方时获胜,每匹马只能出场一次。
\hspace{15pt}现在你已经知道了齐威王的马匹上场的顺序,将在第一、二、三场上场的马匹速度分别为 v_1,v_2,v_3。同时,你也已经知道了田忌所拥有的马匹速度,分别为 a_1,a_2,a_3
\hspace{15pt}你可以调整田忌的马匹出场顺序,你能否帮助田忌赢得这场比赛?

输入描述:
\hspace{15pt}第一行输入三个整数 v_1,v_2,v_3 \left(1 \leq v_i \leq 9\right) 代表齐威王按上场顺序的马匹速度。
\hspace{15pt}第二行输入三个整数 a_1,a_2,a_3 \left(1 \leq a_i \leq 9\right) 代表田忌拥有的马匹速度。顺序可以任意调整。


输出描述:
\hspace{15pt}如果田忌可以获胜,直接输出 \rm Yes,否则输出 \rm No
示例1

输入

3 2 1
1 2 3

输出

Yes

说明

\hspace{15pt}在这个样例中,田忌可以在第一局派出速度为 1 的马匹,在第二局派出速度为 3 的马匹,在第三局派出速度为 2 的马匹。如此一来,他会赢得两局比赛,从而获胜。
示例2

输入

2 2 2
2 2 3

输出

No
list_v = list(map(int, input().split()))
list_a = list(map(int, input().split()))
list_a.sort()
count_win = 0
for i in list_v:
    for j in list_a:
        if j > i:
            count_win = count_win + 1
            list_a.remove(j)
if count_win >= 2:
    print("Yes")
else:
    print("No")

发表于 2026-03-30 21:17:03 回复(0)
a, b = sorted(list(map(int, input().split()))), sorted(list(map(int, input().split())))
print("Yes" if a[0] < b[1] and a[1] < b[2] else "No")

发表于 2026-01-17 17:50:22 回复(0)
import sys

a = sorted(sys.stdin.readline().split())
b = sorted(sys.stdin.readline().split())
c=0
for i in range(2):
    for j in range(2):
        if a[i]<b[j]:
            c+=1
if c<1:
    print("No")
else:
    print("Yes")
发表于 2025-12-03 21:15:36 回复(0)
list1=list(map(int,input().split(" ")))
list2=list(map(int,input().split(" ")))
count=0 for i in list1: for j in list2: if i<j:
            count+=1 if count>=3: print("Yes") else: print("No")
发表于 2025-09-29 15:42:00 回复(0)
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.sort()
b.sort()
if b[2]>a[1] and b[1]>a[0]:
    print('Yes')
else:
    print('No')
发表于 2025-09-19 22:10:19 回复(0)
v = list(map(int,input().split()))
a = list(map(int,input().split()))
v = sorted(v)
a = sorted(a)
if a[2]>v[1] and a[1]>v[0]:
    print('Yes')
else:
    print('No')
发表于 2025-08-24 15:55:07 回复(0)
v=list(map(int,input().split()))
v.sort()
a=list(map(int,input().split()))
a.sort()
if a[1]>v[0] and a[2]>v[1]:
    print('Yes')
else:
    print('No')
发表于 2025-08-12 15:27:05 回复(0)
import sys
# 三种不同的方法
q = list(map(int,input().split()))
t = list(map(int,input().split()))
max1 = 0
for i in range(3):
    count = 0
    for j in range(3):
        if t[j] > q[i]:
            count += 1
    max1 = max(max1,count)
if max1 > 1:
    print('Yes')
else:
    print('No')

# q.sort()
# t.sort()
# if t[2] > q[1] and t[1] > q[0]:
#     print('Yes')
# else:
#     print('No')

# t.sort()
# q.sort()
# count = 0
# if t[2] > q[1]:
#     count += 1
# if t[1] > q[0]:
#     count += 1
# if count > 1:
#     print('Yes')
# else:
#     print('No')
发表于 2025-07-08 16:32:48 回复(0)
v=list(map(int, input().split()))
a=list(map(int, input().split()))

v.sort()
a.sort()
count=0

if a[2] > v[1] and a[1] > v[0]:
    count+=1

if count ==1:
    print('Yes')
else:
    print('No')
发表于 2025-06-30 22:00:18 回复(0)
qi  =list(map(int,input().split()))
tian=list(map(int,input().split()))

qi.sort(reverse=True)
tian.sort(reverse=True)
# print(qi)
# print(tian)
i=0             #用i表示每一轮比赛后 qi的最大值的下标
j=0             #用i表示每一轮比赛后 tian的最大值的下标
k=0             # k用来计数,k<2  (当田忌的前两匹速度最快的马比完赛,比赛结果就可知了,此时去判断win是否大于2)
win=0           # win表示赢的场次数
while k<2:
    if tian[j] > qi[i]:        
        j +=1
        i +=1
        k +=1
        win+=1
    else:
        i+=1
        if i>2:
            break
if win >=2:
    print("Yes")
else:
    print("No")
发表于 2025-06-24 10:26:52 回复(0)