-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Петров, 5, 15, 16, 17 #69
Open
fromfall
wants to merge
25
commits into
MikhailErofeev:master
Choose a base branch
from
fromfall:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
8db6838
Create lab10.py
fromfall ddacc86
Create test10.py
fromfall e39508b
Create lab11.py
fromfall a36ed7f
Create test11.py
fromfall 4813fe5
Create lab9.py
fromfall 444ec11
Create lab14.py
fromfall a6e74c3
Create test14.py
fromfall 38f9c7f
Create lab18.py
fromfall 43dae0e
Create test18.py
fromfall 0fdb29d
Create lab19.py
fromfall 375ad09
Create test19.py
fromfall 777c257
Create lab20.py
fromfall 9d19ed6
Create test20.py
fromfall a31e86b
Create kruskal.py
fromfall 696be3c
Create test17.py
fromfall 5c87929
Create union_find.py
fromfall c5ba764
Create lab5.py
fromfall 763016a
Create lab16.py
fromfall c93f932
Create test16.py
fromfall 2530501
Create lab15.py
fromfall bbc9a2a
Create test15.py
fromfall 09f2069
Update lab15.py
fromfall 00f733c
Update test15.py
fromfall 853907d
Update lab16.py
fromfall 1fdb0c5
Update test16.py
fromfall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from sys import stdin | ||
|
||
def f(A): | ||
if len(A) == 0: | ||
return [] | ||
A.sort() | ||
b = [] | ||
for i in A: | ||
if not i in b: | ||
b.append(i) | ||
A = b | ||
res = 0 | ||
for c in A: | ||
l = len(A) - 1 | ||
for a in A: | ||
while (l > 0 and c ** 2 - a ** 2 < A[l] ** 2): | ||
l -= 1 | ||
if (c ** 2 - a ** 2 == A[l] ** 2 and A[l] < a): | ||
res += 1 | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import unittest | ||
import random | ||
from lab10 import f | ||
|
||
class TestPythagoras(unittest.TestCase): | ||
def testmain(self, c): | ||
B = [] | ||
for i in c: | ||
if not i in B: | ||
B.append(i) | ||
expected = 0 | ||
for i in range(len(B)): | ||
for j in range(i + 1, len(B)): | ||
for k in range(j + 1, len(B)): | ||
if B[i]**2 + B[j]**2 == B[k]**2: | ||
expected += 1 | ||
res = f(B) | ||
self.assertEqual(res, expected) | ||
|
||
def test_empty(self): | ||
self.testmain([]) | ||
|
||
def test_std(self): | ||
self.testmain([23, 247, 19, 96, 264, 265, 132, 265, 181]) | ||
|
||
def test_duplicates(self): | ||
self.testmain([3, 4, 3, 3, 5, 4, 1, 1, 1, 4, 5, 3, 4, 2, 2, 2, 5, 5, 4, 3, 2]) | ||
|
||
def test_random(self): | ||
c = [randint(-11111, 11111) for i in range(111)] | ||
self.testmain(c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from sys import stdin | ||
#a = list(map(int, stdin.readline().split())) | ||
|
||
def f(A): | ||
res = 0 | ||
c = -1 | ||
s = 0 | ||
for i in range(len(A)): | ||
if A[i] >= c: | ||
res = max(res, s) | ||
s = 0 | ||
c = A[i] | ||
else: | ||
s += c - A[i] | ||
c = -1 | ||
s = 0 | ||
for i in range(0, len(A), -1): | ||
if A[i] >= c: | ||
res = max(res, s) | ||
s = 0 | ||
c = A[i] | ||
else: | ||
s += c - A[i] | ||
return res | ||
|
||
#print(f(a)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import unittest | ||
import random | ||
import lab11 | ||
|
||
class TestSorting(unittest.TestCase): | ||
|
||
def test_trivial(self): | ||
arr = [1, 333, 22] | ||
res = lab11.f(arr) | ||
expected = 0 | ||
self.assertEqual(expected, res) | ||
|
||
def test_empty(self): | ||
arr = [] | ||
res = lab11.f(arr) | ||
expected = 0 | ||
self.assertEqual(expected, res) | ||
|
||
def test_moun(self): | ||
arr = ([1, 10, 0, 0, 0, 11]) | ||
res = lab11.f(arr) | ||
expected = 30 | ||
self.assertEqual(expected, res) | ||
|
||
def test_std(self): | ||
arr = [2, 5, 1, 2, 3, 4, 7, 7, 6] | ||
res = lab11.f(arr) | ||
expected = 10 | ||
self.assertEqual(expected, res) | ||
|
||
def test_moun1(self): | ||
arr = [10, 1, 1, 1, 1, 1, 1, 1, 1, 10] | ||
res = lab11.f(arr) | ||
expected = 72 | ||
self.assertEqual(expected, res) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import random | ||
|
||
|
||
class Heap: | ||
a = [] | ||
def _down(self, i): | ||
while 2 * i + 1 < len(self.a): | ||
left = 2 * i + 1 | ||
right = 2 * i + 2 | ||
j = left | ||
if right < len(self.a) and self.a[right] < self.a[left]: | ||
j = right | ||
if self.a[i] <= self.a[j]: | ||
break | ||
self.a[i], self.a[j] = self.a[j], self.a[i] | ||
i = j | ||
def _up(self, i): | ||
while i > 0 and self.a[i] < self.a[(i - 1) // 2]: | ||
self.a[i], self.a[(i - 1) // 2] = self.a[(i - 1) // 2], self.a[i] | ||
i = (i - 1) // 2 | ||
def min(self): | ||
res = self.a[0] | ||
if (len(self.a) > 1): | ||
self.a[0] = self.a.pop() | ||
else: | ||
self.a.pop() | ||
self._down(0) | ||
return res | ||
def insert(self, k): | ||
self.a.append(k) | ||
self._up(len(self.a) - 1) | ||
|
||
def part1(a, k): | ||
h = Heap() | ||
for i in a: | ||
h.insert(i) | ||
if (len(h.a) > k): | ||
h.min() | ||
return h.a | ||
|
||
def _partition(a, l, r): | ||
t = [a[random.randint(l, r)], a[l], a[r]] | ||
if t[0] > t[1]: | ||
t[0], t[1] = t[1], t[0] | ||
if t[1] > t[2]: | ||
t[1], t[2] = t[2], t[1] | ||
if t[0] > t[1]: | ||
t[0], t[1] = t[1], t[0] | ||
x = t[1] | ||
i = l | ||
j = r | ||
while 1: | ||
while a[i] < x: | ||
i = i + 1 | ||
while a[j] > x: | ||
j = j - 1 | ||
if i < j: | ||
a[i], a[j] = a[j], a[i] | ||
i += 1 | ||
j -= 1 | ||
else: | ||
return j | ||
|
||
|
||
def part2(a, n): | ||
left = 0 | ||
right = len(a) - 1 | ||
k = len(a) - n - 1 | ||
b = sorted(a) | ||
while 1: | ||
mid = _partition(a, left, right) | ||
if mid == k: | ||
return a[-n:] | ||
elif k < mid: | ||
right = mid | ||
else: | ||
left = mid + 1 | ||
|
||
|
||
def test(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тесты в отдельном файле с помощью unittest, пожалуйста |
||
a = random.sample(range(100), 50) + random.sample(range(100), 50) | ||
r1 = part1(a, 40) | ||
r2 = part2(a, 40) | ||
r = sorted(a)[-40:] | ||
print(r == sorted(r1)) | ||
print(r == sorted(r2)) | ||
|
||
test() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
вы нашли медиану между 3 случайными точками, кажется этого не достаточно, чтобы добиться O(n), как требовалось в задании