It's too easy and it feels strange. After all, the level of ABC these days is too high ...
Whether you can add small ones to make a big one
answerA.py
x=list(map(int,input().split()))
x.sort()
if x[0]+x[1]==x[2]:
print("Yes")
else:
print("No")
To find the area of the rectangle, it is sufficient to know the x, y coordinates in the lower left and the x, y coordinates in the upper right, and since the rectangle narrows from the given information, it is sufficient to classify the cases based on the value of a. Also, a2-a1 and a4-a3 can be-respectively, but in that case a rectangle cannot be created, so it must be set to 0.
answerB.py
w,h,n=map(int,input().split())
a1,a2,a3,a4=0,w,0,h
for i in range(n):
x,y,a=map(int,input().split())
if a==1:
a1=max(a1,x)
elif a==2:
a2=min(a2,x)
elif a==3:
a3=max(a3,y)
else:
a4=min(a4,y)
print(max(a2-a1,0)*max(a4-a3,0))
Since it can be seen that one continuous color section is inverted by one operation, it can be seen that the number of sections is reduced by one by this operation. Therefore, since it is sufficient to repeat this operation to make all into one section, the number of sections-1 is the number of stones to be obtained. In addition, the number of intervals can be easily obtained by using a self-made group by function.
answerC.py
def groupby(a):
a2=[[a[0],1]]
for i in range(1,len(a)):
if a2[-1][0]==a[i]:
a2[-1][1]+=1
else:
a2.append([a[i],1])
return a2
s=groupby(input())
print(len(s)-1)
Since the problem statement is very long, I thought it was a difficult problem, but nothing was difficult and I missed the beat. (It took me a long time to get ready. ** I want to get used to the long sentences! **)
First of all, since you have 0 apples at the beginning and buy and sell with a total of T apples, you can see that if you buy and sell T // 2 apples together in the city where the difference in amount is maximum, the profit will be maximum. I will. Therefore, ** what you want to find is the city group (i, j) ** that maximizes the difference in amount. If you move both of the town groups here, the amount of calculation will increase, so I paid attention to ** of the two towns, which sells apples **. At this time, the city i where you should buy apples is uniquely determined. This is because apples are the cheapest of the cities 1 to j-1. Also, at this time, if the apple is looking for the cheapest city among the cities 1 to j-1 for each city j, the calculation amount is 0 ($ n ^ 2 $) and it is not in time, so ** cumulative sum The minimum of adjacent objects is calculated ** ("minimum in town 1 ~ j" is equal to "minimum in town 1 ~ j-1 and minimum between town j"). Therefore, you can reduce the profit by lowering or raising the price of one apple (only one yen) for the group of cities where the difference in the amount of money is the largest, so ** Count the number of groups of such cities. It's good ** (Since the price of apples is different in each city, you can simply count the number of pairs. If you have apples of the same price, you can reduce the profit at a lower cost, but it depends on the restrictions There are no apples of the same price in the city.)
answerD.py
n,t=map(int,input().split())
a=list(map(int,input().split()))
x=[0]*n
x[0]=a[0]
for i in range(1,n):
x[i]=min(x[i-1],a[i])
d=dict()
for i in range(1,n):
y=a[i]-x[i-1]
if y>0:
if y in d:
d[y]+=1
else:
d[y]=1
d=list(d.items())
d.sort(reverse=True)
print(d[0][1])
Recommended Posts