From 6463cabbc0e9409ef1c5a90c26b5aed77d5c6ee1 Mon Sep 17 00:00:00 2001 From: Azureki Date: Sun, 21 Apr 2019 12:16:17 +0800 Subject: [PATCH] contest-133 --- 1029. Two City Scheduling/better-soln.py | 11 ++++++++ 1029. Two City Scheduling/main.py | 28 ++++++++++++++++++++ 1030. Matrix Cells in Distance Order/main.py | 12 +++++++++ 3 files changed, 51 insertions(+) create mode 100644 1029. Two City Scheduling/better-soln.py create mode 100644 1029. Two City Scheduling/main.py create mode 100644 1030. Matrix Cells in Distance Order/main.py diff --git a/1029. Two City Scheduling/better-soln.py b/1029. Two City Scheduling/better-soln.py new file mode 100644 index 0000000..7759380 --- /dev/null +++ b/1029. Two City Scheduling/better-soln.py @@ -0,0 +1,11 @@ +class Solution: + def twoCitySchedCost(self, costs: List[List[int]]) -> int: + costs.sort(key = lambda x: x[0]-x[1]) + + N = len(costs) // 2 + cost = 0 + for i in range(N): + cost += costs[i][0] + for i in range(N): + cost += costs[N+i][1] + return cost diff --git a/1029. Two City Scheduling/main.py b/1029. Two City Scheduling/main.py new file mode 100644 index 0000000..ec6f6c1 --- /dev/null +++ b/1029. Two City Scheduling/main.py @@ -0,0 +1,28 @@ +import itertools + + +class Solution: + def twoCitySchedCost(self, costs): + def get_diff(cost): + return abs(cost[0]-cost[1]) + + res = 0 + N = len(costs)//2 + d = {0: 0, 1: 0} + lst = sorted(costs, key=get_diff, reverse=True) + for cost in lst: + idx = 0 if cost[0] List[List[int]]: + + def get_distance(point1): + return abs(point1[1]-c0)+ abs(point1[0]-r0) + + it = itertools.product(range(R),range(C)) + return sorted(list(it), key = get_distance) +