1. Заголовок темы должен быть информативным. В противном случае тема удаляется ... 2. Все тексты программ должны помещаться в теги [code=pas] ... [/code], либо быть опубликованы на нашем PasteBin в режиме вечного хранения. 3. Прежде чем задавать вопрос, см. "FAQ", если там не нашли ответа, воспользуйтесь ПОИСКОМ, возможно такую задачу уже решали! 4. Не предлагайте свои решения на других языках, кроме Паскаля (исключение - только с согласия модератора). 5. НЕ используйте форум для личного общения, все что не относится к обсуждению темы - на PM! 6. Одна тема - один вопрос (задача) 7.Проверяйте программы перед тем, как разместить их на форуме!!! 8.Спрашивайте и отвечайте четко и по существу!!!
я предполагал, что is_enemy[] - двумерный массив 6х6, такой, что is_enemy[x, y] = true тогда и только тогда, когда депутаты номер х и у - враги.
фрагмент реального кода для депутата с будет выглядеть так:
if (c = a) and (is_enemy[3,1]) the inc(c_enemies); if (c = b) and (is_enemy[3,2]) the inc(c_enemies); if (c = d) and (is_enemy[3,4]) the inc(c_enemies); if (c = e) and (is_enemy[3,5]) the inc(c_enemies); if (c = f) and (is_enemy[3,6]) the inc(c_enemies);
а вот в этом месте нужно вывести результат:
if f_enemies > m then continue; //вот здесь end;
вывод результата будет такой: выводишь 6 строк вида "депутата Х помещаем в палату У".
var is_enemy:array [1..6,1..6] of integer; a,b,c,d,e,f,m:integer; a_enemies: integer; b_enemies: integer; c_enemies: integer; d_enemies: integer; e_enemies: integer; f_enemies: integer; procedure sortirovka; begin for a:=1 to 2 do for b:=1 to 2 do for c:=1 to 2 do for d:=1 to 2 do for e:=1 to 2 do for f:=1 to 2 do begin a_enemies:=0; if (a = b) and (is_enemy[1,2]) the inc(a_enemies); if (a = c) and (is_enemy[1,3]) the inc(a_enemies); if (a = d) and (is_enemy[1,4]) the inc(a_enemies); if (a = e) and (is_enemy[1,5]) the inc(a_enemies); if (a = f) and (is_enemy[1,6]) the inc(a_enemies); if a_enemies > m then continue; b_enemies:=0; if (b = a) and (is_enemy[2,1]) the inc(b_enemies); if (b = c) and (is_enemy[2,3]) the inc(b_enemies); if (b = d) and (is_enemy[2,4]) the inc(b_enemies); if (b = e) and (is_enemy[2,5]) the inc(b_enemies); if (b = f) and (is_enemy[2,6]) the inc(b_enemies); if b_enemies > m then continue; c_enemies:=0; if (c = a) and (is_enemy[3,1]) the inc(c_enemies); if (c = b) and (is_enemy[3,2]) the inc(c_enemies); if (c = d) and (is_enemy[3,4]) the inc(c_enemies); if (c = e) and (is_enemy[3,5]) the inc(c_enemies); if (c = f) and (is_enemy[3,6]) the inc(c_enemies); if c_enemies > m then continue; c_enemies:=0; if (d = a) and (is_enemy[4,1]) the inc(d_enemies); if (d = b) and (is_enemy[4,2]) the inc(d_enemies); if (d = c) and (is_enemy[4,3]) the inc(d_enemies); if (d = e) and (is_enemy[4,5]) the inc(d_enemies); if (d = f) and (is_enemy[4,6]) the inc(d_enemies); if d_enemies > m then continue; e_enemies:=0; if (e = a) and (is_enemy[5,1]) the inc(e_enemies); if (e = b) and (is_enemy[5,2]) the inc(e_enemies); if (e = c) and (is_enemy[5,3]) the inc(e_enemies); if (e = d) and (is_enemy[5,4]) the inc(e_enemies); if (e = f) and (is_enemy[5,6]) the inc(e_enemies); if e_enemies > m then continue; f_enemies:=0; if (f = a) and (is_enemy[6,1]) the inc(f_enemies); if (f = b) and (is_enemy[6,2]) the inc(f_enemies); if (f = c) and (is_enemy[6,3]) the inc(f_enemies); if (f = e) and (is_enemy[6,5]) the inc(f_enemies); if (f = d) and (is_enemy[6,4]) the inc(f_enemies); if f_enemies > m then continue; if a_enemies>m then writeln ('Pomeshaem deputata A v palatu 2'); if b_enemies>m then writeln ('Pomeshaem deputata B v palatu 2'); if c_enemies>m then writeln ('Pomeshaem deputata C v palatu 2'); if d_enemies>m then writeln ('Pomeshaem deputata D v palatu 2'); if e_enemies>m then writeln ('Pomeshaem deputata E v palatu 2'); if f_enemies>m then writeln ('Pomeshaem deputata F v palatu 2') end; begin Writeln ('Kolichestvo vragov m: ',m); Readln (m); Sortirovka; Writeln ('The end'); end.
const n = 6; type TEnemies = set of byte; TRelationship = array [1..n] of TEnemies;
function Intersect(const i, j, k: byte; const iSet, jSet, kSet: TEnemies): boolean; begin Intersect := (i in jSet + kSet) or (j in iSet + kSet) or (k in iSet + jSet); end;
var r: TRelationship = ( ([]), // враги первого (пусто в данном случае) ([4]), // враги второго ([4, 5]), // 3 ([3, 2]), // 4 ([3]), // 5 ([]) // 6 );
i, j, k, l, id: byte; idx: array [1..3] of byte;
begin for i := 1 to n - 2 do for j := i + 1 to n - 1 do for k := j + 1 to n do if not Intersect(i, j, k, r[i], r[j], r[k]) then begin id := 0; for l := 1 to n do if (l <> i) and (l <> j) and (l <> k) then begin inc(id); idx[id] := l; end; if not Intersect(idx[1], idx[2], idx[3], r[idx[1]], r[idx[2]], r[idx[3]]) then writeln('Group A: (', i, ',', j, ',', k, ') Group B: (', idx[1], ',', idx[2], ',', idx[3], ')'); end; end.
Сообщение отредактировано: klem4 -
--------------------
perl -e 'print for (map{chr(hex)}("4861707079204E6577205965617221"=~/(.{2})/g)), "\n";'