9.23 Where to go for the written test

1. Gang's live broadcast

Time limit: 3000MS
Memory limit: 589824KB
Title description: In
2020, live streaming has become a new weapon for pre-sales of Qunar hotels. Qunar.com CEO Gang wants to select n from the company’s m employees to participate in his live broadcast. Knowing that m is less than 100, how many options are there?
Enter description

m(公司员工数)
n (挑选的员工数)

Output description

p(挑选方法)

Sample input

4
2

Sample output

6

Idea
This question is the problem of solving the combination number. The final solution target is C mn C_m^nCmn.
Code

m = int(input())
n = int(input())
re,div = 1,1
for i in range(n):
    re*=m-i
    div*=(i+1)
print(re//div)

2. The first period of demand-2021 school recruitment questions

Time limit: 5000MS
Memory limit: 589824KB
Topic description:
Every Tuesday when Qunar.com collectively needs the Final Review. Regarding the order of the ticket quotations, operation director Xiaotian and product director Lao Feng have some different opinions. Xiaotian thinks the offer The order should be based on the order of a, f, d, e, z to do the quotation list sorting, Lao Feng thinks that the list should be sorted in the order of f, a, e, d, z, the two can't dispute, the technical director here When I stood up, I thought that most of them were in agreement, and only a few were inconsistent. You can start with the order of agreement as a first issue, and then do it after the dispute. Then if the first issue is based on combining Xiaotian and Lao If Feng's quotation sequence agrees with each other, the quotations are listed first, then the maximum number of quotations can be sorted.
Enter description

7(多少个报价)
a b c d e f g
b d a c f g e

Output description

4(b d f g)

Sample input

7
a b c d e f g
b d a c f g e

Sample output

4

Idea The
longest common subsequence problem is solved by dp.
Code

N = int(input())
yy = input().split()
cp = input().split()
dp = [[0]*N for _ in range(N)]
for i in range(N):
    if yy[i]==cp[0]:
        dp[i][0]=dp[0][i]=1
    if cp[i]==yy[0]:
        dp[i][0]=dp[0][i]=1
for i in range(1,N):
    for j in range(1,N):
        if yy[i]==cp[j]:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])+1
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])
print(dp[-1][-1])

3. Card type analysis of playing cards-2021 technology

Time limit: 3000MS
Memory limit: 589824KB
Title description:
The pattern of Texas Hold'em is composed of N poker cards 0 <N <8. The card types that can be composed are distinguished from high to low in value:

1.皇家同花顺:最高为Ace(一点)的同花顺。
如A K Q J 10 的同花顺
2.同花顺:同一花色,五张顺序的牌。
如:K Q J 10 9 的同花顺
3.四条:有四张同一点数的牌。
如:4 4 4 4 9
4.葫芦:三张同一点数的牌,加一对其他点数的牌。
如:3 3 3 10 10
5.同花:五张同一花色的牌。
如:J 10 8 7 5 的全是红桃的牌
6.顺子:五张顺连的牌。
如:5 4 3 2 A 的非同花牌(此牌型为最小的顺子)
7.三条:仅有三张同一点数的牌,其余两张点数不同。
如: 9 9 9 5 3
8:两对:两张相同点数的牌,加另外两张相同点数的牌。
如:K K 5 5 2
9.一对:仅有两张相同点数的牌。
如:10 10 9 4 2
10.高牌:不符合上面任何一种牌型的牌型,由单牌且不连续不同花的组成,以点数决定大小。
如:A 10 9 5 3 的非同花的牌

These ten card types are output HuangJiaTongHuaShun, TongHuaShun, SiTiao, HuLu, TongHua, ShunZi, SanTiao, LiangDui, YiDui, GaoPai
playing cards have 4 suits, respectively (S means spades, H means hearts, C means grass flowers, D Represents a square piece)
The input of this question is any N cards less than 8 and
the result is the highest type among these cards.
Enter description

2(牌数为2)
SA HA (两张牌为黑桃A 红心A)

Output description

YiDui (结果为一对)

Sample input

5
SA SK SQ SJ S10

Sample output

HuangJiaTongHuaShun

Thinking
the problem need to consider all possible scenarios, first consider all colors possible scenarios; after considering the number of all cases (four, three, gourd ...) Finally, consider the straight condition.
Code

N = int(input())
pocket = input().split()
from collections import defaultdict
huase = defaultdict(list)
pik = defaultdict(list)
for i in pocket:
    huase[i[0]].append(i[1:])
    pik[i[1:]].append(i[0])
re = ['HuangJiaTongHuaShun','TongHuaShun','SiTiao','HuLu','TongHua','ShunZi','SanTiao','LiangDui','YiDui','GaoPai']
res = [len(re)-1]
a = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
for t in 'SHCD':
    if len(huase[t])>=5:
        res.append(4)
        temp = [a.index(i) for i in huase[t]]
        if 12 in temp:
            temp.append(-1)
        temp.sort(reverse=True)
        for i in range(len(temp)-4):
            if temp[i]-4==temp[i+4]:
                if temp[i]==12:
                    res.append(0)
                else:
                    res.append(1)
for i in a:
    if len(pik[i])==4:
        res.append(2)
    if len(pik[i])==3:
        if 6 in res or 8 in res:
            res.append(3)
        res.append(6)
    if len(pik[i])==2:
        if 6 in res:
            res.append(3)
        if 8 in res:
            res.append(7)
        res.append(8)
t = [a.index(i) for i in pik if pik[i]!=[]]
if len(t)>=5:
    if 12 in t:
        t.append(-1)
    t.sort(reverse=True)
    for i in range(len(t)-4):
        if t[i]-4==t[i+4]:
            res.append(5)
print(re[min(res)])

Guess you like

Origin blog.csdn.net/jhaos/article/details/108766537