AtCoder Beginner Contest 069 Review of past questions

The second past question that I have solved before

Time required

スクリーンショット 2019-12-24 12.11.47.png

Problem A

You can understand if you think of the figure

answerA.py


n,m=map(int,input().split())
print((n-1)*(m-1))

B problem

Negative index convenient

answerB.py


s=input()
l=len(s)
print(s[0]+str(l-2)+s[-1])

C problem

Impression that was difficult when I first saw it before If you think of it as a multiple of 4 (①), a multiple of 2 that is not a multiple of 4, (②), and an odd number (③), you can come before and after ①, and ① before and after ②. Or ② needs to be, ① needs to come before and after ③. Therefore, ** first line up from ③, which has strict restrictions **. If you think about it for a moment, arranging ① and ③ alternately is a way of arranging so that ③ satisfies the condition, but ① is less used. If you arrange in this way, there is no problem if the remaining ② are arranged continuously. Considering such an arrangement, it becomes as follows. (Cases will occur.)

IMG_1698.JPG

I tried to solve it quickly and the if statement became redundant, so I rewrote it in the comment out.

answerC.py


n=int(input())
a=[int(i) for i in input().split()]
x,y,z=0,0,0
for i in range(n):
    if a[i]%4==0:
        x+=1
    elif a[i]%2==0:
        y+=1
    else:
        z+=1
if y>0:
    if z<=x:
        print("Yes")
    else:
        print("No")
else:
    if z<=x+1:
        print("Yes")
    else:
        print("No")
'''
if y==0:
    x+=1
if z<=x:
    print("Yes")
else:
    print("No")
'''

D problem

Personally, C was more difficult, and I think I saw it before a problem similar to this one. N kinds of colors are given and painted so that they are connected vertically and horizontally. At this time, you can decide how to apply ** by yourself , so you can apply it horizontally so that all of them are connected (choose the one you like, either horizontally or vertically !!). At this time, the even-numbered lines (starting from 0) are painted from left to right, and the odd-numbered lines are painted from right to left. Also, it is good to keep information about which color you are currently painting. ( It is convenient to keep a separate information about what information you have for tracing problems **) Also, since it is convenient to be able to loop in the opposite direction with the recently learned for j in range (w-1, -1, -1):, I will actively use it. (It is decided to decrement the loop variable with the third argument)

answerD.py


h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

hw=[[0 for i in range(w)] for i in range(h)]

k=0#Where are you looking now
for i in range(h):
    if i%2==0:
        for j in range(w):
            if a[k]==0:
                k+=1
            hw[i][j]=k+1
            a[k]-=1
    else:
        for j in range(w-1,-1,-1):
            if a[k]==0:
                k+=1
            hw[i][j]=k+1
            a[k]-=1
for i in range(h):
    print(" ".join(map(str,hw[i])))

Recommended Posts

AtCoder Beginner Contest 102 Review of past questions
AtCoder Beginner Contest 072 Review of past questions
AtCoder Beginner Contest 085 Review of past questions
AtCoder Beginner Contest 062 Review of past questions
AtCoder Beginner Contest 051 Review of past questions
AtCoder Beginner Contest 127 Review of past questions
AtCoder Beginner Contest 119 Review of past questions
AtCoder Beginner Contest 151 Review of past questions
AtCoder Beginner Contest 075 Review of past questions
AtCoder Beginner Contest 110 Review of past questions
AtCoder Beginner Contest 117 Review of past questions
AtCoder Beginner Contest 070 Review of past questions
AtCoder Beginner Contest 105 Review of past questions
AtCoder Beginner Contest 112 Review of past questions
AtCoder Beginner Contest 076 Review of past questions
AtCoder Beginner Contest 089 Review of past questions
AtCoder Beginner Contest 069 Review of past questions
AtCoder Beginner Contest 079 Review of past questions
AtCoder Beginner Contest 056 Review of past questions
AtCoder Beginner Contest 087 Review of past questions
AtCoder Beginner Contest 067 Review of past questions
AtCoder Beginner Contest 093 Review of past questions
AtCoder Beginner Contest 046 Review of past questions
AtCoder Beginner Contest 123 Review of past questions
AtCoder Beginner Contest 049 Review of past questions
AtCoder Beginner Contest 078 Review of past questions
AtCoder Beginner Contest 081 Review of past questions
AtCoder Beginner Contest 047 Review of past questions
AtCoder Beginner Contest 060 Review of past questions
AtCoder Beginner Contest 104 Review of past questions
AtCoder Beginner Contest 057 Review of past questions
AtCoder Beginner Contest 121 Review of past questions
AtCoder Beginner Contest 126 Review of past questions
AtCoder Beginner Contest 090 Review of past questions
AtCoder Beginner Contest 103 Review of past questions
AtCoder Beginner Contest 061 Review of past questions
AtCoder Beginner Contest 059 Review of past questions
AtCoder Beginner Contest 044 Review of past questions
AtCoder Beginner Contest 083 Review of past questions
AtCoder Beginner Contest 048 Review of past questions
AtCoder Beginner Contest 124 Review of past questions
AtCoder Beginner Contest 116 Review of past questions
AtCoder Beginner Contest 097 Review of past questions
AtCoder Beginner Contest 088 Review of past questions
AtCoder Beginner Contest 092 Review of past questions
AtCoder Beginner Contest 099 Review of past questions
AtCoder Beginner Contest 065 Review of past questions
AtCoder Beginner Contest 053 Review of past questions
AtCoder Beginner Contest 094 Review of past questions
AtCoder Beginner Contest 063 Review of past questions
AtCoder Beginner Contest 107 Review of past questions
AtCoder Beginner Contest 071 Review of past questions
AtCoder Beginner Contest 064 Review of past questions
AtCoder Beginner Contest 082 Review of past questions
AtCoder Beginner Contest 084 Review of past questions
AtCoder Beginner Contest 068 Review of past questions
AtCoder Beginner Contest 058 Review of past questions
AtCoder Beginner Contest 043 Review of past questions
AtCoder Beginner Contest 098 Review of past questions
AtCoder Beginner Contest 114 Review of past questions
AtCoder Beginner Contest 045 Review of past questions