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
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