AtCoder Beginner Contest 366 - python前三题

A - Election 2 

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100100 points

Problem Statement

A mayoral election is being held in AtCoder City. The candidates are Takahashi and Aoki.

There are N valid votes cast for either of the two candidates, and the counting is currently underway. Here, N is an odd number.

The current vote count is T votes for Takahashi and A votes for Aoki.

Determine if the outcome of the election is already decided at this point.

问题陈述

AtCoder 市正在举行市长选举。候选人是高桥和青木。

有 N 张有效选票投给两位候选人中的任何一位,目前正在进行计票。这里, N 是奇数。

目前的计票结果是:高桥 T 票,青木 A 票。

请判断此时选举结果是否已经确定。

Constraints

  • 1≤N≤99
  • NN is an odd number.
  • 0≤T,A≤N
  • T+A≤N
  • All input values are integers.
限制因素
  • 1≤N≤99
  • N 是奇数。
  • 0≤T,A≤N
  • T+A≤N
  • 所有输入值均为整数。

Input

The input is given from standard input in the following format:

N T A

Output

Print Yes if the outcome of the election is already decided, and No otherwise.

Sample Input 1Copy

7 4 2

Sample Output 1Copy

Yes

Even if the remaining one vote goes to Aoki, Takahashi will still win. That is, his victory is decided, so print Yes.

Sample Input 2Copy

99 12 48

Sample Output 2Copy

No

Although Aoki currently has more votes, Takahashi would win if he receives the remaining 3939 votes. Therefore, print No.

Sample Input 3Copy

1 0 0

Sample Output 3Copy

No

 

# 简单签到题,直接算一下即可
# A
n,t,a = map(int,input().split())
if n - t - a + min(t,a) >= max(t,a):
    print("No")
else:
    print("Yes")

B - Vertical Writing 

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200 points

Problem Statement

You are given a horizontally written text. Convert it to vertical writing, filling spaces with *.

You are given N strings S1,S2,…,SN​ consisting of lowercase English letters. Let M be the maximum length of these strings.

Print M strings T1,T2,…,TM​ that satisfy the following conditions:

  • Each Ti consists of lowercase English letters and *.
  • Each Ti does not end with *.
  • For each 1≤i≤N, the following holds:
    • For each 1≤j≤∣Si∣, the (N−i+1)-th character of Tjexists, and the concatenation of the (N−i+1)-th characters of T1,T2,…,T∣Si∣​ in this order equals SiSi​.
    • For each ∣Si∣+1≤j≤M, the (N−i+1)-th character of Tj either does not exist or is *.

Here, ∣Si∣ denotes the length of the string Si.

问题陈述

给你一个横向书写的文本。将其转换为竖写,用 * 填充空格。

给你 N 个由小写英文字母组成的字符串 S1,S2,…,SN​ 。设 M 为这些字符串的最大长度。

打印满足以下条件的 M 字符串 T1,T2,…,TM​ :

  • 每个 Ti​ 由小写英文字母和 * 组成。
  • 每个 Ti​ 都不以 * 结尾。
  • 每个 1≤i≤N都满足以下条件:
    • 对于每个 1≤j≤∣Si∣ , Tj​ 的 (N−i+1) 个字符存在, T1,T2,…,T∣Si∣​ 的 (N−i+1) 个字符按此顺序连接等于 Si 。
    • 对于每一个 ∣Si∣+1≤j≤M, Tj的 (N−i+1)个字符要么不存在,要么是 "*"。

这里, ∣Si∣ 表示字符串 Si 的长度。

Constraints

  • N is an integer between 11 and 100100, inclusive.
  • Each Si is a string of lowercase English letters with length between 1 and 100, inclusive.
限制因素
  • N 是介于 1 和 100 之间的整数,包括首尾两个整数。
  • 每个 Si​ 都是长度介于 1 和 100 之间的小写英文字母字符串。

Input

The input is given from Standard Input in the following format:

N
S1
S2
⋮⋮
SN

Output

Print the answer in the following format:

T1
T2
⋮⋮
TM

Sample Input 1Copy

3
abc
de
fghi

Sample Output 1Copy

fda
geb
h*c
i

Placing * as the 2nd character of T3​ puts the c in the correct position. On the other hand, placing * as the 2nd and 3rd characters of T4​ would make T4​ end with *, which violates the condition.

Sample Input 2Copy

3
atcoder
beginner
contest

Sample Output 2Copy

cba
oet
ngc
tio
end
sne
ter
*r
# 数据量不大纯模拟就行
# B
n = int(input())
m = float("-inf")
l1 = []
for _ in range(n):
    s = input()
    l1.append(s)
    m = max(m,len(s))
l2 = ["" for _ in range(m)]
for i in range(n):
    for j in range(m):
        try:
            l2[j] += l1[i][j]
        except:
            l2[j] += "*"
for i in l2:
    i = i[::-1]
    if i[-1] == "*":
        j = len(i) - 1
        while i[j] == "*":
            j -= 1
        print(i[:j + 1])
    else:
        print(i)

 C - Balls and Bag Query 

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300 points

Problem Statement

You have an empty bag. You are given Q queries, which must be processed in order.

There are three types of queries.

  • 1 x : Put one ball with the integer x written on it into the bag.
  • 2 x : Remove one ball with the integer x written on it from the bag and discard it. It is guaranteed that the bag has a ball with the integer x written on it when this query is given.
  • 3 : Print the number of different integers written on the balls in the bag.
问题陈述

你有一个空袋子。给你 Q 个查询,必须按顺序处理。

有三种查询。

  • 1 x :将一个写有整数 x 的球放入袋子中。
  • 2 x : 从袋子中取出一个写有整数 x 的球并丢弃。当给出这个查询时,可以保证袋子中有一个写着整数 x 的球。
  • 3 : 打印袋中写有不同整数的球的个数。

Constraints

  • 1≤Q≤2*10**5
  • 1≤x≤10**6
  • When a query of the second type is given, the bag has a ball with the integer x written on it.
  • There is at least one query of the third type.
  • All input values are integers.
限制因素
  • 1≤Q≤2×10**5
  • 1≤x≤10**6
  • 当给出第二个类型的查询时,袋子里有一个写有整数 x 的球。
  • 至少有一个第三种类型的查询。
  • 所有输入值都是整数。

Input

The input is given from Standard Input in the following format:

QQ
query1
query2
⋮⋮
queryQ

The i-th queryi​ is given in one of the following three formats:

1 x
2 x
3

Output

If there are K queries of the third type, print K lines. The i-th line (1≤i≤K) should contain the answer to the i-th query of the third type.

Sample Input 1Copy

8
1 3
1 1
1 4
3
2 1
3
1 5
3

Sample Output 1Copy

3
2
3

Initially, the bag is empty.

For the first query 1 3, a ball with the integer 3 written on it enters the bag.

For the second query 1 1, a ball with the integer 1 written on it enters the bag.

For the third query 1 4, a ball with the integer 4 written on it enters the bag.

For the fourth query 3, the bag has balls with the integers 1,3,4, so print 3.

For the fifth query 2 1, a ball with the integer 1 written on it is removed from the bag.

For the sixth query 3, the bag has balls with the integers 3,4, so print 2.

For the seventh query 1 5, a ball with the integer 5 written on it enters the bag.

For the eighth query 3, the bag has balls with the integers 3,4,5, so print 3.

Sample Input 2Copy

8
1 2
1 2
3
2 2
1 4
1 4
2 2
3

Sample Output 2Copy

1
1
# 由于数据量比较大,所以删除和增加要o(1)的时间复杂度才行,字典就可以解决,然后再加一些判断即可
# C
q = int(input())
ans = 0
dict1 = {}
for _ in range(q):
    x = list(map(int,input().split()))
    if x[0] == 3:
        print(ans)
    if x[0] == 1:
       if x[1] in dict1:
           if dict1[x[1]] == 0:
               ans += 1
               dict1[x[1]] += 1
           elif dict1[x[1]] > 0:
               dict1[x[1]] += 1
       else:
           dict1[x[1]] = 1
           ans += 1
    if x[0] == 2:
        if dict1[x[1]] == 1 and dict1[x[1]] > 0:
            ans -= 1
            dict1[x[1]] -= 1
        elif dict1[x[1]] > 1:
            dict1[x[1]] -= 1

你可能感兴趣的:(python,算法)