Войти
или
Зарегистрироваться
Курсы
Учебник
Учебник 2.0
ОГЭ/ЕГЭ
Олимпиады
Рубрикатор
Компилятор
Онлайн Компилятор
Компилятор Python (lite)
Редактор HTML Code
Статья Автор:
Щурова Ольга
ЕГЭ-27
clstr1=[] clstr2=[] def dist(x1,y1,x2,y2): return ((x2-x1)**2+(y2-y1)**2)**0.5 def centr(cl): md=10**6 for x in cl: d=0 for y in cl: if x!=y: d+=dist(x[0],x[1],y[0],y[1]) if d<md: md=d c=x print(d) return c def clstr(v): for n in v: if n[1]<3: clstr1.append(n) else: clstr2.append(n) v=[] with open('27A.txt') as file: for line in file: v.append(list(map(float,line.split()))) clstr(v) print(len(clstr1),len(clstr2)) c1=centr(clstr1) c2=centr(clstr2) print(c1,c2) px=(c1[0]+c2[0])/2 py=(c1[1]+c2[1])/2 print(int(px*10_000),int(py*10_000)) #at=1,task=5 clstr1=[] clstr2=[] clstr3=[] def dist(x1,y1,x2,y2): return ((x2-x1)**2+(y2-y1)**2)**0.5 def centr(cl): d,md=0,10**6 for x in cl: for y in cl: d+=dist(x[0],x[1],y[0],y[1]) if d<md: md=d c=x d=0 return c def clstr(v): for n in v: if n[1]<1.3*(n[0]-4): clstr1.append(n) elif n[1]<-2*n[0]+12: clstr2.append(n) else: clstr3.append(n) v=[] with open('27B.txt') as file: for line in file: v.append(list(map(float,line.split()))) clstr(v) print(len(clstr1),len(clstr2),len(clstr3)) c1=centr(clstr1) c2=centr(clstr2) c3=centr(clstr3) px=(c1[0]+c2[0]+c3[0])/3 py=(c1[1]+c2[1]+c3[1])/3 print(int(px*10_000),int(py*10_000))
×
# at=1,task=3 clstr1=[] clstr2=[] clstr3=[] def dist(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5 def centr(cl): md=10**6 for p1 in cl: d=0 for p2 in cl: d+=dist(p1[0],p1[1],p2[0],p2[1]) if d<md: md=d c=p1 return c def clstr(v): for n in v: x,y=n[0],n[1] if y>-0.5*(x-7): clstr1.append(n) else: if x<3: clstr2.append(n) elif x>4: clstr3.append(n) else: if y>x-4.25: clstr2.append(n) else: clstr3.append(n) v=[] with open('27-13b.txt') as file: for line in file: v.append(list(map(float,line.replace(',','.').split()))) clstr(v) print(len(clstr1),len(clstr2),len(clstr3)) c1=centr(clstr1) c2=centr(clstr2) c3=centr(clstr3) px=(c1[0]+c2[0]+c3[0])/3 py=(c1[1]+c2[1]+c3[1])/3 print(int(px*10_000),int(py*10_000))
×
Чтобы оставить комментарий нужна авторизация
Печать