2016 Feb Bronze Problem 3 Load Balancing: Difference between revisions

From Wiki
Jump to navigation Jump to search
No edit summary
 
(3 intermediate revisions by one other user not shown)
Line 6: Line 6:


== Solution ==
== Solution ==
the input B is not used in this situation.
You find every possible x and y coordinates of the fence by adding 1 and minus 1 on each a and b input


== Code ==
== Code ==
Line 14: Line 16:
[[Category:Brute Force]]
[[Category:Brute Force]]
[[Category:Simulation]]
[[Category:Simulation]]
import sys
sys.stdin = open("balancing.in", "r")
sys.stdout = open("balancing.out", "w")
n,b = map(int,input().split())
x_val = []
y_val = []
x_fen = []
h_fen = []
for _ in range(n):
x, y = map(int,input().split())
x_val.append(x)
y_val.append(y)
x_fen.append(x + 1) 
h_fen.append(x + 1)
min_balance = n
for v_y in x_fen:
for h_x in h_fen:
tl,tr,bl,br = 0,0,0,0
for k in range(n):
x,y = x_val[k],y_val[k]
if x > h_x and y > v_y:
tl+=1
elif x < h_x and y > v_y:
tr+=1
elif x > h_x and y < v_y:
bl+=1
else:
br+=1
min_balance = min(min_balance, max(tl,tr,bl,br))
print(min_balance)

Latest revision as of 00:13, 11 January 2024

Official Problem Statement[edit]

Load Balancing

Problem[edit]

Solution[edit]

the input B is not used in this situation. You find every possible x and y coordinates of the fence by adding 1 and minus 1 on each a and b input

Code[edit]

import sys

sys.stdin = open("balancing.in", "r") sys.stdout = open("balancing.out", "w")

n,b = map(int,input().split())

x_val = [] y_val = [] x_fen = [] h_fen = []

for _ in range(n): x, y = map(int,input().split()) x_val.append(x) y_val.append(y) x_fen.append(x + 1) h_fen.append(x + 1)

min_balance = n

for v_y in x_fen: for h_x in h_fen:

tl,tr,bl,br = 0,0,0,0 for k in range(n): x,y = x_val[k],y_val[k] if x > h_x and y > v_y: tl+=1 elif x < h_x and y > v_y: tr+=1 elif x > h_x and y < v_y: bl+=1 else: br+=1

min_balance = min(min_balance, max(tl,tr,bl,br))

print(min_balance)