This commit is contained in:
augustin64 2024-05-29 18:11:10 +02:00
parent 1c80215edb
commit 472d5c4610
7 changed files with 260 additions and 0 deletions

View File

@ -0,0 +1,11 @@
def main():
n, stu_num = map(int, input().split())
res = [list(map(int, input().split())) for _ in range(n)]
res.sort(key=lambda x:x[1], reverse=True)
dico = {res[i][0]:i+1 for i in range(len(res))}
print(dico[stu_num])
for _ in range(int(input())):
main()

View File

@ -0,0 +1,25 @@
import math
def isPrime(num):
if(num==1):
return False
if(num==2):
return True
if(num%2==0):
return False
i = 3
while(i<math.sqrt(num)+1):
if num%i==0:
return False
i += 2
return True
def main():
n = int(input())
ids = list(map(int, input().split()))
print(len([i for i in ids if isPrime(i)]))
for _ in range(int(input())):
main()

View File

@ -0,0 +1,79 @@
class GFG:
def __init__(self,graph):
# residual graph
self.graph = graph
self.ppl = len(graph)
self.jobs = len(graph[0])
# A DFS based recursive function
# that returns true if a matching
# for vertex u is possible
def bpm(self, u, matchR, seen):
# Try every job one by one
for v in range(self.jobs):
# If applicant u is interested
# in job v and v is not seen
if self.graph[u][v] and seen[v] == False:
# Mark v as visited
seen[v] = True
'''If job 'v' is not assigned to
an applicant OR previously assigned
applicant for job v (which is matchR[v])
has an alternate job available.
Since v is marked as visited in the
above line, matchR[v] in the following
recursive call will not get job 'v' again'''
if matchR[v] == -1 or self.bpm(matchR[v],
matchR, seen):
matchR[v] = u
return True
return False
# Returns maximum number of matching
def maxBPM(self):
'''An array to keep track of the
applicants assigned to jobs.
The value of matchR[i] is the
applicant number assigned to job i,
the value -1 indicates nobody is assigned.'''
matchR = [-1] * self.jobs
# Count of jobs assigned to applicants
result = 0
for i in range(self.ppl):
# Mark all jobs as not seen for next applicant.
seen = [False] * self.jobs
# Find if the applicant 'u' can get a job
if self.bpm(i, matchR, seen):
result += 1
return result
def main():
n, m = map(int, input().split())
friendships = [list(map(int, input().split())) for _ in range(m)]
graph = []
for i in range(n):
line = [0]*(2*n)
graph.append(line)
for a, b in friendships:
graph[a-1][n+b-1] = 1
for i in range(n):
line = [0]*(2*n)
graph.append(line)
print(GFG(graph).maxBPM())
for _ in range(int(input())):
main()

View File

@ -0,0 +1,25 @@
"""PARTIEL BUG: les rendus 3, 2 et 2, 3 sont considérés comme distincts"""
m = 1000000007
def main():
n, target = map(int, input().split())
dollars = [int(i) for i in input().split() if int(i) != 0]
manieres = [0 for _ in range(target+1)]
manieres[0] = 1
for k in range(1, target+1):
man = 0
for coin in dollars:
if coin <= k:
#print("coin:", coin)
man += manieres[k-coin]
#print(k, man)
manieres[k] = man%m
print(manieres)
return manieres[target]
for _ in range(int(input())):
print(main())

View File

@ -0,0 +1,32 @@
m = 15546404183
def main():
n = int(input())
s = input()
left_rolling_hash = 0
right_rolling_hash = 0
pw = 1
def roll_left(h, l):
return (h*37+l)%m
def roll_right(h, l, pw):
rs = (h+l*pw)%m
pw = (pw*37)%m
return rs, pw
total = 0
for i in range(n-1):
left_rolling_hash = roll_left(left_rolling_hash, ord(s[i]))
right_rolling_hash, pw = roll_right(right_rolling_hash, ord(s[-1-i]), pw)
if left_rolling_hash == right_rolling_hash:
total += 1
# print(left_rolling_hash, right_rolling_hash)
return total
for _ in range(int(input())):
print(main())

View File

@ -0,0 +1,76 @@
"""PARTIEL BUG"""
from collections import defaultdict
import heapq
class Graph:
def __init__(self, n):
self.graph = defaultdict(list)
self.n = n
self.seats = None
def set_seats(self, seats, n):
self.seats = [(i in seats) for i in range(n)]
def add_edge(self, u, v, weight=1):
self.graph[u].append((weight, v))
def bfs(self, s):
heap = []
visited = [False] * (self.n + 1)
heapq.heappush(heap, (0, s))
visited[s] = True
while heap:
prio, s = heapq.heappop(heap)
if self.seats[s]:
return prio
for w, v in self.graph[s]:
if not visited[v]:
heapq.heappush(heap, (w+prio, v))
visited[v] = True
return float("inf")
def main():
# nb of seats, V, E
k, n, m = map(int, input().split())
# Prepare Graph
students = [int(i)-1 for i in input().split()]
seats = [int(i)-1 for i in input().split()]
g = Graph(n)
g.set_seats(seats, n)
for i in range(m):
a, b, c = input().split()
g.add_edge(int(a)-1, int(b)-1, weight=int(c))
# BFS from each of the students to determine the fastest
dists = []
for st in students:
dists.append(g.bfs(st))
mini = float("inf")
best = -1
for i in range(k):
if dists[i] < mini:
mini = dists[i]
best = i
elif dists[i] == mini:
return "impossible"
if best == -1:
return "impossible"
return students[best]+1
for _ in range(int(input())):
print(main())

View File

@ -0,0 +1,12 @@
import random
print(1)
k, n, m = random.randint(2, 20), random.randint(2, 100), random.randint(0, 1000)
print(k, n, m)
print(" ".join([str(i) for i in random.choices(range(0, n), k=k)]))
print(" ".join([str(i) for i in random.choices(range(0, n), k=k)]))
for i in range(m):
print(random.choice(range(0, n)), random.choice(range(0, n)), random.randint(0, 1000))