[PYTHON] AtCoder Beginner Contest 167 Memorandum

at first

Those who have come to refer to this article. Sorry. A, B, C, D understood A - Registration

s==t[0:-1]#(I mean[:-1]But I feel good...)

B - Easy Linear Programming If you pull the number in order, it's ok Dirty source code.

def j():
    a,b,c,k=map(int,input().split())
    o=0
    x=k
    if a!=0:
        o+=a
        k-=a
        if k==0:
            return a
        elif k<0:
            return x
    if b!=0:
        k-=b
        if k<=0:
            return a
    if c!=0:
        k-=c
        o-=c
        if k==0:
            return o
        elif k<0:
            return o-k
print(j())

C - Skill Up I skipped it. Not good at all searches. By the next time, learn.

Postscript It seems that it can be done by bit search. So learn I tried it. As a result, it was a one-shot clear. The bit search method turned out to be convenient.

n,m,x=map(int,input().split())
item=[list(map(int,input().split()))for i in range(n)]#Gold, algorithm up number
bag=[]#How to buy a book that meets the conditions
for i in range(2**n):#Examine all
    temp=[]#Books to buy
    job=[0]*m#Comprehension
    for s in range(n):#Examine all digits
        if (i>>s)&1:#If you buy
            temp.append(s)#Add books to buy
            for y in range(m):
                job[y]+=item[s][y+1]#Add comprehension
    for s in range(len(job)):
        if job[s]<x:#If the comprehension is less than X, break
            break
    else:#If all comprehension is X or higher
        money=0
        for s in temp:#Calculate the total amount
            money+=item[s][0]
        bag.append(money)
#If there is not more than one combination to buy-Output 1
print(min(bag) if len(bag)>=1 else -1)

D - Teleporter If you turn K times for, it will only be TLE, so you can go if there is a surplus at the beginning and end of the loop. I thought, but I couldn't go. Someone tell me. By the way, an example of a problem sentence is made.


n,k=map(int,input().split())
a=[int(i)-1 for i in input().split()]
ed=[False]*n
go=0
c=0
cc=0
while not ed[go]:#End if you have already passed
    print(a[go]+1)
    ed[go]=True
    go=a[go]
    c+=1
ed=[False]*n
print()
while not ed[go]:#The second loop can be different 6,5,2,5,3,In case of 2, 6,2,5,3,2,5,3,2,5,...Becomes
    print(a[go]+1)
    ed[go]=True
    go=a[go]
    cc+=1#Save as another variable
print()
for i in range((k-c)%cc):
    print(a[go]+1)
    go=a[go]
print()
print(go+1)

Postscript I could do it by putting together while, saving the value without turning print with for, and adding the output when the loop was never looped.

n,k=map(int,input().split())
a=[int(i)-1 for i in input().split()]
p=0
visited=[0]*n
first=[]
roop=[]
while visited[p]!=2:#Stop if you go twice
    if visited[p]==0:#I went for the first time
        first.append(p)
    else:#Passed once
        roop.append(p)
    visited[p]+=1#Make a mark
    p=a[p]#Teleport
if len(first)>k:#If it never loops
    print(first[k]+1)#First kth
else:
    print(roop[(k-(len(first)-len(roop)))%len(roop)]+1)#Otherwise, subtract the first loop and the second loop from k, and the surplus of the number of times of the second loop

Finally

E and F couldn't reach. It was my third challenge, but it was difficult. I thought I had to learn more algorithms and be able to think logically. By the way, the new Rating is 68.

Recommended Posts

AtCoder Beginner Contest 167 Memorandum
AtCoder Beginner Contest 177
AtCoder Beginner Contest 179
AtCoder Beginner Contest 172
AtCoder Beginner Contest 180
AtCoder Beginner Contest 173
Atcoder Beginner Contest 153
AtCoder Beginner Contest 152 Review
AtCoder Beginner Contest 181 Note
AtCoder Beginner Contest 187 Note
AtCoder Beginner Contest 160 Review
AtCoder Beginner Contest 178 Review
AtCoder Beginner Contest 180 Note
AtCoder Beginner Contest 166 Review
AtCoder Beginner Contest 167 Review
AtCoder Beginner Contest 182 Note
AtCoder Beginner Contest 164 Review
AtCoder Beginner Contest 169 Review
AtCoder Beginner Contest 181 Review
AtCoder Beginner Contest 171 Review
AtCoder Beginner Contest 182 Review
AtCoder Beginner Contest 180 Review
AtCoder Beginner Contest 156 WriteUp
AtCoder Beginner Contest 177 Review
AtCoder Beginner Contest 168 Review
AtCoder Beginner Contest 179 Review
AtCoder Beginner Contest 172 Review
AtCoder Beginner Contest 183 Note
AtCoder Beginner Contest 176 Review
AtCoder Beginner Contest 184 Note
AtCoder Beginner Contest 175 Review
AtCoder Beginner Contest 174 Review
AtCoder Beginner Contest 153 Review
AtCoder Beginner Contest 156 Review
AtCoder Beginner Contest 161 Review
AtCoder Beginner Contest 170 Review
AtCoder Beginner Contest 165 Review
AtCoder Beginner Contest 173 Review
AtCoder Beginner Contest 188 Note
AtCoder Beginner Contest 155 Review
AtCoder Beginner Contest 162 Review
AtCoder Beginner Contest 181 Participation Report
AtCoder Beginner Contest 175 Virtual entry
AtCoder Beginner Contest 161 Participation Report
AtCoder Beginner Contest 151 Participation Report
AtCoder Beginner Contest 176 Participation Report
AtCoder Beginner Contest 154 Participation Report
AtCoder Beginner Contest # 003 Participation Note
AtCoder Beginner Contest 166 Participation Report
AtCoder Beginner Contest # 002 C Problem
AtCoder Beginner Contest 145 Participation Report
AtCoder Beginner Contest 184 Participation Report
AtCoder Beginner Contest 165 Participation Report
AtCoder Beginner Contest 160 Participation Report
AtCoder Beginner Contest 169 Participation Report
AtCoder Beginner Contest 159 Participation Report
AtCoder Beginner Contest 164 Participation Report
AtCoder Beginner Contest 168 Participation Report
AtCoder Beginner Contest 150 Participation Report
AtCoder Beginner Contest 158 Participation Report
AtCoder Beginner Contest 180 Participation Report