Ejemplo n.º 1
0
from genarr import genRandomArr
n = int(input("N: "))

a = genRandomArr(n)
print(a)
b = []

i = 3
while i < n:
    b.append(a[i])
    i += 3
print(b)
Ejemplo n.º 2
0
from genarr import genRandomArr
n = int(input("N: "))

a = genRandomArr(n, 0, 5)
print(a)

b, c = [], []

i = 0
cnt = 1
while i < n - 1:
    if a[i] == a[i + 1]:
        cnt += 1
    else:
        b.append(cnt)
        c.append(a[i])
        cnt = 1
    i += 1
print("B", b)
print("C", c)
Ejemplo n.º 3
0
from genarr import genRandomArr

n = int(input("N: "))

a = genRandomArr(n, 0, 30)
print(a)

b = []
for i in range(n):
    b.append(i)

for i in range(n - 1):
    for j in range(n - 1):
        if a[b[j]] > a[b[j + 1]]:
            b[j], b[j + 1] = b[j + 1], b[j]

print(b)

#Для наглядности
for i in range(n):
    print(a[b[i]])
Ejemplo n.º 4
0
import math
from genarr import genRandomArr
x,y = [], []

n = int(input("N: "))

x,y = genRandomArr(n,-10,10), genRandomArr(n,-10,10)

def distanse(x1,y1,x2,y2):
    return(math.sqrt((x2-x1)**2 + (y2-y1)**2))

mp = 1000

for i in range(len(x)):
    print(x[i],y[i])
    for j in range(i+1, len(x)):
        for k in range(j+1, len(x)):
            a = distanse(x[i], y[i], x[j], y[j])
            b = distanse(x[k], y[k], x[j], y[j])
            c = distanse(x[k], y[k], x[i], y[i])
            if a+b+c < mp:
                mp = a+b+c
                i1,i2,i3 = i,j,k

print((x[i1],y[i1]), (x[i2],y[i2]), (x[i3],y[i3]),mp)
Ejemplo n.º 5
0
from genarr import genRandomArr
n = int(input("N: "))

a = genRandomArr(n,-10,10)
print(a)

i = 0
while i < len(a):
    if a[i] < 0:
        a.insert(i+1,0)
        i += 2
    else:
        i += 1

print(a)
Ejemplo n.º 6
0
from genarr import genRandomArr
n = int(input("N: "))

a = genRandomArr(n, 2, 5)
print(a)

i = 0
while i < len(a) - 1:
    if a[i] != a[i + 1]:
        a.pop(i)
        i -= 1
    i += 1
#     print(a)

a.pop(len(a) - 1)

print(a)
Ejemplo n.º 7
0
from genarr import genRandomArr
#Самое простое решение O = n^2
n = int(input("N: "))
a = genRandomArr(n, 0, 10)
print(a)

b = []
cnt = 0

for i in range(n):
    for j in range(i + 1, n):
        if a[i] == a[j]:
            if a[i] not in b:
                b.append(a[i])
                cnt += 2
            else:
                cnt += 1

print(cnt)
Ejemplo n.º 8
0
import math
from genarr import genRandomArr
x1, y1 = [], []
x2, y2 = [], []
n1 = int(input("N1: "))
n2 = int(input("N2: "))

x1, y1 = genRandomArr(n1, -10, 10), genRandomArr(n1, -10, 10)
x2, y2 = genRandomArr(n2, -10, 10), genRandomArr(n2, -10, 10)

print(x1)
print(y1)
print()
print(x2)
print(y2)
print()


def distanse(x1, y1, x2, y2):
    return (math.sqrt((x2 - x1)**2 + (y2 - y1)**2))


mind = 10000

for i in range(len(x1)):
    for j in range(len(x2)):
        d = distanse(x1[i], y1[i], x2[j], y2[j])
        if d < mind:
            ii, jj = i, j
            maxd = d