Форум » Электронные таблицы » Задача 4783 (три точки и координатная четверть) » Ответить

Задача 4783 (три точки и координатная четверть)

ivackov.sergey: Ответ не совпадает! У меня получилось 2674 vs 1856? [pre2] ## procedure f(xi, yi: char; c1, c2, c3, c4: List<integer>); //Добавление точки в одну из четвертей begin if (xi = '1') and (yi = '1') then C1.Add(1); if (xi = '-') and (yi = '1') then C2.Add(1); if (xi = '-') and (yi = '-') then C3.Add(1); if (xi = '1') and (yi = '-') then C4.Add(1); if (xi = '0') and (yi = '-') then begin C3.Add(1); C4.Add(1); //34 end; if (xi = '0') and (yi = '1') then begin C1.Add(1); C2.Add(1); //12 end; if (xi = '1') and (yi = '0') then begin C1.Add(1); C4.Add(1); //14 end; if (xi = '-') and (yi = '0') then begin C2.Add(1); C3.Add(1); //23 end; if (xi = '0') and (yi = '0') then begin C1.Add(1); C2.Add(1); C3.Add(1); C4.Add(1); end; end; {Формаьт текстового файла -79 47 22 76 21 16 -83 86 -80 -64 48 47 80 -1 79 -7 11 44 } Assign(input, '567.txt'); var c := 0; while not (eof) do begin var x := ReadlnString; var s := x.towords; var (x1, x2, x3) := (s[0].ToInteger, s[1].ToInteger, s[2].ToInteger); var (y1, y2, y3) := (s[3].ToInteger, s[4].ToInteger, s[5].ToInteger); var C1 := new List<integer>; var C2 := new List<integer>; var C3 := new List<integer>; var C4 := new List<integer>; f(sign(x1).ToString[1], sign(y1).ToString[1], c1, c2, c3, c4); f(sign(x2).ToString[1], sign(y2).ToString[1], c1, c2, c3, c4); f(sign(x3).ToString[1], sign(y3).ToString[1], c1, c2, c3, c4); if C1.Count + C2.Count + C3.Count + C4.Count <= 3 then begin if (c1.Count = 2) or (c2.Count = 2) or (c3.Count = 2) or (c4.Count = 2) then begin inc(c); //println(c1.Count,c2.Count,c3.Count,c4.Count,C1.Count + C2.Count + C3.Count + C4.Count); end; end; end; c.Print; [/pre2]

Ответов - 3

Поляков: Спасибо за замечание. Правильный ответ - 2713. [pre2] p1, p2, p3 = [], [], [] for s in open('9-138.csv'): x1, x2, x3, y1, y2, y3 = map( int, s.split(';') ) p1.append( (x1, y1) ) p2.append( (x2, y2) ) p3.append( (x3, y3) ) def theSameQuater( p1, p2 ): return p1[0]*p2[0] > 0 and p1[1]*p2[1] > 0 k = [0]*3 for i in range(len(p1)): if theSameQuater(p1[ i],p2[ i]) and not theSameQuater(p2[ i],p3[ i]): k[0] += 1 if theSameQuater(p1[ i],p3[ i]) and not theSameQuater(p2[ i],p3[ i]): k[1] += 1 if theSameQuater(p2[ i],p3[ i]) and not theSameQuater(p2[ i],p1[ i]): k[2] += 1 print( k, sum(k) )[/pre2]

timsc1: на паскале можно так: сохраняем таблицу в txt файл; «## var lines := ReadAllLines('138.txt'); var (k1,k2,k3,k4):=(0,0,0,0); var x1,x2,x3,y1,y2,y3:integer; var res := Matr(lines.ConvertAll(l->l.ToIntegers[:6])).Cols; for var i:=0 to res[0].Length-1 do begin x1:=res[0]; x2:=res[1]; x3:=res[2]; y1:=res[3]; y2:=res[4]; y3:=res[5]; //1 if (x1>0) and (y1>0) and (x2>0) and (y2>0) and not((x3>0) and (y3>0))then k1+=1; if (x1>0) and (y1>0) and (x3>0) and (y3>0) and not((x2>0) and (y2>0))then k1+=1; if (x3>0) and (y3>0) and (x2>0) and (y2>0) and not((x1>0) and (y1>0))then k1+=1; //3 if (x1<0) and (y1<0) and (x2<0) and (y2<0) and not((x3<0) and (y3<0))then k3+=1; if (x1<0) and (y1<0) and (x3<0) and (y3<0) and not((x2<0) and (y2<0))then k3+=1; if (x3<0) and (y3<0) and (x2<0) and (y2<0) and not((x1<0) and (y1<0))then k3+=1; //2 if (x1<0) and (y1>0) and (x2<0) and (y2>0) and not((x3<0) and (y3>0))then k2+=1; if (x1<0) and (y1>0) and (x3<0) and (y3>0) and not((x2<0) and (y2>0))then k2+=1; if (x3<0) and (y3>0) and (x2<0) and (y2>0) and not((x1<0) and (y1>0))then k2+=1; //4 if (x1>0) and (y1<0) and (x2>0) and (y2<0) and not((x3>0) and (y3<0))then k4+=1; if (x1>0) and (y1<0) and (x3>0) and (y3<0) and not((x2>0) and (y2<0))then k4+=1; if (x3>0) and (y3<0) and (x2>0) and (y2<0) and not((x1>0) and (y1<0))then k4+=1; end; print(k1+k2+k3+k4);»

GasDM21: А можно и в Excel Вспомогательные столбцы I, G, H используются для отображения в какой четверти находится каждая точка Для строки 2 в этих столбцах такие формулы: I2: [pre2] =ЕСЛИ(И(A2>0;D2>0);1;ЕСЛИ(И(A2>0;D2<0);4;ЕСЛИ(И(A2<0;D2>0);2;ЕСЛИ(И(A2<0;D2<0);3;"ось"))))[/pre2] G2: [pre2] =ЕСЛИ(И(B2>0;E2>0);1;ЕСЛИ(И(B2>0;E2<0);4;ЕСЛИ(И(B2<0;E2>0);2;ЕСЛИ(И(B2<0;E2<0);3;"ось"))))[/pre2] H2: [pre2] =ЕСЛИ(И(C2>0;F2>0);1;ЕСЛИ(И(C2>0;F2<0);4;ЕСЛИ(И(C2<0;F2>0);2;ЕСЛИ(И(C2<0;F2<0);3;"ось"))))[/pre2] Столбец J хранит "маркер" - удовлетворяют ли координаты троек условиям задачи. [pre2]=ЕСЛИ(ИЛИ(И(G2=H2;H2<>I2;G2<>"ось");И(H2=I2;I2<>G2;H2<>"ось");И(G2=I2;H2<>G2;G2<>"ось"));1;"")[/pre2] А сам ответ - это сумма "маркеров"




полная версия страницы