A - Election 2
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 100100 points
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 票。
请判断此时选举结果是否已经确定。
The input is given from standard input in the following format:
N T A
Print Yes
if the outcome of the election is already decided, and No
otherwise.
7 4 2
Yes
Even if the remaining one vote goes to Aoki, Takahashi will still win. That is, his victory is decided, so print Yes
.
99 12 48
No
Although Aoki currently has more votes, Takahashi would win if he receives the remaining 3939 votes. Therefore, print No
.
1 0 0
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
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:
*
.*
.*
.Here, ∣Si∣ denotes the length of the string Si.
给你一个横向书写的文本。将其转换为竖写,用
*
填充空格。
给你 N 个由小写英文字母组成的字符串 S1,S2,…,SN 。设 M 为这些字符串的最大长度。
打印满足以下条件的 M 字符串 T1,T2,…,TM :
*
组成。*
结尾。这里, ∣Si∣ 表示字符串 Si 的长度。
The input is given from Standard Input in the following format:
N S1 S2 ⋮⋮ SN
Print the answer in the following format:
T1 T2 ⋮⋮ TM
3 abc de fghi
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.
3 atcoder beginner contest
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
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
: 打印袋中写有不同整数的球的个数。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
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.
8 1 3 1 1 1 4 3 2 1 3 1 5 3
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.
8 1 2 1 2 3 2 2 1 4 1 4 2 2 3
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