Advertisement
Guest User

326-1-all.dpr

a guest
Apr 1st, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 8.01 KB | None | 0 0
  1. program one;
  2. var
  3. a:array [1..1000,1..2] of integer;
  4. i,j,n,k:integer;
  5. b:array [1..1000] of boolean;
  6. l,p:integer;
  7.  
  8.  
  9.  
  10. procedure check;
  11. var
  12. i1,i2,i3:integer;
  13. ar:array[1..1000] of integer;
  14. c:integer;
  15. begin
  16. for i1:=1 to n do
  17. for i2:=1 to n do
  18. if (i1<>i2)and(b[i1])and(b[i2]) then
  19. begin
  20. for i3:=1 to n do
  21. begin
  22. if ((a[i3,1]=i1)and(a[i3,2]=i2))or((a[i3,1]=i2)and(a[i3,2]=i1)) then exit;
  23. end;
  24. end;
  25.  
  26. c:=0;
  27. for i1:=1 to n do
  28. if b[i1] then
  29. begin
  30. inc(c);
  31. ar[c]:=i1;
  32. end;
  33. if c=k then
  34. begin
  35. for i1:=1 to c do
  36. begin
  37. write(ar[i1],' ');
  38. end;
  39. halt(0);
  40. end;
  41. end;
  42.  
  43.  
  44. begin
  45. assign(input,'tournament.in');
  46. assign(output,'tournament.out');
  47. reset(input);
  48. rewrite(output);
  49. readln(n);
  50. for i:=1 to n do
  51. read(a[i,1],a[i,2]);
  52. readln(k);
  53. fillchar(b,sizeof(b),0);
  54. l:=1;
  55. p:=1;
  56. for i:=1 to n do l:=l*2;
  57. for i:=1 to l do
  58. begin
  59. p:=1;
  60. if b[p] then
  61. begin
  62. while b[p] do
  63. begin b[p]:=false; inc(p);
  64. end;
  65. b[p]:=true;
  66. end else b[p]:=true;
  67.  
  68. check;
  69. end;
  70. writeln('0');
  71. close(input);
  72. close(output);
  73. end.
  74.  
  75.  
  76. { NEXT }
  77.  
  78.  
  79.  
  80. Program tournament;
  81. var
  82. n:integer;
  83. k:integer;
  84. a:array[1..10000,1..2] of integer;
  85. b:array[1..10000] of boolean;
  86. i,j:integer;
  87. l,c,lgrp:integer;
  88. g1:array[1..10000,1..2]of integer;
  89. count:integer;
  90. gc:array[1..2] of integer;
  91.  
  92.  
  93. function find(group,lastgroup:integer):integer;
  94. var
  95. i,ff:integer;
  96. begin
  97. for i:=1 to n do
  98. if b[i]=false then
  99. if (a[i,1]=group)or(a[i,2]=group) then
  100. begin
  101. b[i]:=true;
  102. if a[i,1]=group then ff:=a[i,2] else ff:=a[i,1];
  103. inc(gc[lastgroup]);
  104. g1[gc[lastgroup],lastgroup]:=ff;
  105. find:=ff;
  106. exit;
  107. end;
  108. find:=0;
  109. end;
  110.  
  111. begin
  112. assign(input,'tournament.in');
  113. assign(output,'tournament.out');
  114. reset(input);
  115. rewrite(output);
  116. read(n);
  117. for i:=1 to n do read(a[i,1],a[i,2]);
  118. read(k);
  119. gc[1]:=0;
  120. gc[2]:=0;
  121. count:=0;
  122. l:=1;
  123. lgrp:=2;
  124. fillchar(b,sizeof(b),0);
  125. while count<n do
  126. begin
  127. l:=find(l,lgrp);
  128. if l=0 then
  129. begin
  130. for i:=1 to n do if b[i]=false then l:=i;
  131. end else
  132. begin
  133. if lgrp=1 then lgrp:=2 else lgrp:=1;
  134. inc(count);
  135. end;
  136.  
  137. end;
  138.  
  139. if gc[1]>=k then
  140. begin
  141. for i:=1 to k do write(g1[i,1],' ');
  142. end else
  143. begin
  144. if gc[2]>=k then
  145. begin
  146. for i:=1 to k do write(g1[i,2],' ');
  147. end else
  148. begin
  149. writeln('0');
  150. end;
  151. end;
  152. close(input);
  153. close(output);
  154. end.
  155.  
  156.  
  157. { NEXT }
  158.  
  159.  
  160. Program tournament;
  161. var
  162. n:integer;
  163. k:integer;
  164. a:array[1..10000,1..2] of integer;
  165. b:array[1..10000] of boolean;
  166. i,j:integer;
  167. l,c,lgrp:integer;
  168. g1:array[1..10000,1..2]of integer;
  169. count:integer;
  170. gc:array[1..2] of integer;
  171.  
  172.  
  173. function find(group,lastgroup:integer):integer;
  174. var
  175. i,ff:integer;
  176. begin
  177. for i:=1 to n do
  178. if b[i]=false then
  179. if (a[i,1]=group)or(a[i,2]=group) then
  180. begin
  181. b[i]:=true;
  182. if a[i,1]=group then ff:=a[i,2] else ff:=a[i,1];
  183. inc(gc[lastgroup]);
  184. g1[gc[lastgroup],lastgroup]:=ff;
  185. find:=ff;
  186. exit;
  187. end;
  188. find:=0;
  189. end;
  190.  
  191. begin
  192. assign(input,'tournament.in');
  193. assign(output,'tournament.out');
  194. reset(input);
  195. rewrite(output);
  196. read(n);
  197. for i:=1 to n do read(a[i,1],a[i,2]);
  198. read(k);
  199. gc[1]:=0;
  200. gc[2]:=0;
  201. count:=0;
  202. l:=1;
  203. lgrp:=2;
  204. fillchar(b,sizeof(b),0);
  205. while count<n do
  206. begin
  207. l:=find(l,lgrp);
  208. if l=0 then
  209. begin
  210. for i:=1 to n do if b[i]=false then l:=i;
  211. end else
  212. begin
  213. if lgrp=1 then lgrp:=2 else lgrp:=1;
  214. inc(count);
  215. end;
  216.  
  217. end;
  218.  
  219. if gc[1]>=k then
  220. begin
  221. for i:=1 to k do write(g1[i,1],' ');
  222. end else
  223. begin
  224. if gc[2]>=k then
  225. begin
  226. for i:=1 to k do write(g1[i,2],' ');
  227. end else
  228. begin
  229. writeln('0');
  230. end;
  231. end;
  232. close(input);
  233. close(output);
  234. end.
  235.  
  236.  
  237. { NEXT }
  238.  
  239.  
  240. Program tournament;
  241. var
  242. n:integer;
  243. k:integer;
  244. a:array[1..10000,1..2] of integer;
  245. b:array[1..10000] of boolean;
  246. i,j:integer;
  247. l,c,lgrp:integer;
  248. g1:array[1..10000,1..2]of integer;
  249. count:integer;
  250. gc:array[1..2] of integer;
  251.  
  252. label
  253. wri;
  254.  
  255.  
  256. function find(group,lastgroup:integer):integer;
  257. var
  258. i,ff:integer;
  259. begin
  260. for i:=1 to n do
  261. if b[i]=false then
  262. if (a[i,1]=group)or(a[i,2]=group) then
  263. begin
  264. b[i]:=true;
  265. if a[i,1]=group then ff:=a[i,2] else ff:=a[i,1];
  266. inc(gc[lastgroup]);
  267. g1[gc[lastgroup],lastgroup]:=ff;
  268. find:=ff;
  269. exit;
  270. end;
  271. find:=0;
  272. end;
  273.  
  274. begin
  275. assign(input,'tournament.in');
  276. assign(output,'tournament.out');
  277. reset(input);
  278. rewrite(output);
  279. read(n);
  280. for i:=1 to n do read(a[i,1],a[i,2]);
  281. read(k);
  282. gc[1]:=0;
  283. gc[2]:=0;
  284. count:=0;
  285. l:=1;
  286. lgrp:=2;
  287. fillchar(b,sizeof(b),0);
  288. while count<n do
  289. begin
  290. l:=find(l,lgrp);
  291. if l=0 then
  292. begin
  293. for i:=1 to n do if b[i]=false then l:=i;
  294. if l=0 then goto wri;
  295. end else
  296. begin
  297. if lgrp=1 then lgrp:=2 else lgrp:=1;
  298. inc(count);
  299. end;
  300.  
  301. end;
  302.  
  303. wri:
  304. if gc[1]>=k then
  305. begin
  306. for i:=1 to k do write(g1[i,1],' ');
  307. end else
  308. begin
  309. if gc[2]>=k then
  310. begin
  311. for i:=1 to k do write(g1[i,2],' ');
  312. end else
  313. begin
  314. writeln('0');
  315. end;
  316. end;
  317. close(input);
  318. close(output);
  319. end.
  320.  
  321.  
  322. { NEXT }
  323.  
  324.  
  325. Program tournament;
  326. var
  327. n:integer;
  328. k:integer;
  329. a:array[1..10000,1..2] of integer;
  330. b:array[0..10000] of boolean;
  331. i,j:integer;
  332. l,c,lgrp:integer;
  333. g1:array[1..10000,1..2]of integer;
  334. count:integer;
  335. LL:integer;
  336. gc:array[1..2] of integer;
  337.  
  338. label
  339. wri;
  340.  
  341.  
  342. function find(group,lastgroup:integer):integer;
  343. var
  344. i,ff:integer;
  345. begin
  346. for i:=1 to n do
  347. if b[i]=false then
  348. if (a[i,1]=group)or(a[i,2]=group) then
  349. begin
  350. b[i]:=true;
  351. if a[i,1]=group then ff:=a[i,2] else ff:=a[i,1];
  352. inc(gc[lastgroup]);
  353. g1[gc[lastgroup],lastgroup]:=ff;
  354. find:=ff;
  355. exit;
  356. end;
  357. find:=0;
  358. end;
  359.  
  360. begin
  361. assign(input,'tournament.in');
  362. assign(output,'tournament.out');
  363. reset(input);
  364. rewrite(output);
  365. read(n);
  366. for i:=1 to n do read(a[i,1],a[i,2]);
  367. read(k);
  368. gc[1]:=0;
  369. gc[2]:=0;
  370. count:=0;
  371. l:=1;
  372. lgrp:=2;
  373. fillchar(b,sizeof(b),0);
  374. for LL:=1 to n*n do
  375. begin
  376. l:=find(l,lgrp);
  377. if l=0 then
  378. begin
  379. for i:=1 to n do if b[i]=false then l:=i;
  380. if l=0 then goto wri;
  381. end else
  382. begin
  383. if lgrp=1 then lgrp:=2 else lgrp:=1;
  384. inc(count);
  385. end;
  386.  
  387. end;
  388.  
  389. wri:
  390. if gc[1]>=k then
  391. begin
  392. for i:=1 to k do write(g1[i,1],' ');
  393. end else
  394. begin
  395. if gc[2]>=k then
  396. begin
  397. for i:=1 to k do write(g1[i,2],' ');
  398. end else
  399. begin
  400. writeln('0');
  401. end;
  402. end;
  403. close(input);
  404. close(output);
  405. end.
  406.  
  407.  
  408. { NEXT }
  409.  
  410.  
  411.  
  412. Program tournament;
  413. var
  414. n:integer;
  415. k:integer;
  416. a:array[1..10000,1..2] of integer;
  417. b:array[0..10000] of boolean;
  418. i,j:integer;
  419. l,c,lgrp:integer;
  420. g1:array[1..10000,1..2]of integer;
  421. count:integer;
  422. LL:integer;
  423. gc:array[1..2] of integer;
  424. p:integer;
  425.  
  426. label
  427. wri;
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436. procedure check;
  437. var
  438. i1,i2,i3:integer;
  439. ar:array[1..1000] of integer;
  440. c:integer;
  441. begin
  442. for i1:=1 to n do
  443. for i2:=1 to n do
  444. if (i1<>i2)and(b[i1])and(b[i2]) then
  445. begin
  446. for i3:=1 to n do
  447. begin
  448. if ((a[i3,1]=i1)and(a[i3,2]=i2))or((a[i3,1]=i2)and(a[i3,2]=i1)) then exit;
  449. end;
  450. end;
  451.  
  452. c:=0;
  453. for i1:=1 to n do
  454. if b[i1] then
  455. begin
  456. inc(c);
  457. ar[c]:=i1;
  458. end;
  459. if c=k then
  460. begin
  461. for i1:=1 to c do
  462. begin
  463. write(ar[i1],' ');
  464. end;
  465. halt(0);
  466. end;
  467. end;
  468.  
  469.  
  470.  
  471.  
  472. function find(group,lastgroup:integer):integer;
  473. var
  474. i,ff:integer;
  475. begin
  476. for i:=1 to n do
  477. if b[i]=false then
  478. if (a[i,1]=group)or(a[i,2]=group) then
  479. begin
  480. b[i]:=true;
  481. if a[i,1]=group then ff:=a[i,2] else ff:=a[i,1];
  482. inc(gc[lastgroup]);
  483. g1[gc[lastgroup],lastgroup]:=ff;
  484. find:=ff;
  485. exit;
  486. end;
  487. find:=0;
  488. end;
  489.  
  490. begin
  491. assign(input,'tournament.in');
  492. assign(output,'tournament.out');
  493. reset(input);
  494. rewrite(output);
  495. read(n);
  496. if n<=10 then
  497. begin
  498. for i:=1 to n do
  499. read(a[i,1],a[i,2]);
  500. readln(k);
  501. fillchar(b,sizeof(b),0);
  502. l:=1;
  503. p:=1;
  504. for i:=1 to n do l:=l*2;
  505. for i:=1 to l do
  506. begin
  507. p:=1;
  508. if b[p] then
  509. begin
  510. while b[p] do
  511. begin b[p]:=false; inc(p);
  512. end;
  513. b[p]:=true;
  514. end else b[p]:=true;
  515.  
  516. check;
  517. end;
  518. writeln('0');
  519. close(input);
  520. close(output);
  521. end else
  522. begin
  523.  
  524.  
  525.  
  526. for i:=1 to n do read(a[i,1],a[i,2]);
  527. read(k);
  528. gc[1]:=0;
  529. gc[2]:=0;
  530. count:=0;
  531. l:=1;
  532. lgrp:=2;
  533. fillchar(b,sizeof(b),0);
  534. for LL:=1 to n+1000 do
  535. begin
  536. l:=find(l,lgrp);
  537. if l=0 then
  538. begin
  539. for i:=1 to n do if b[i]=false then l:=i;
  540. if l=0 then goto wri;
  541. end else
  542. begin
  543. if lgrp=1 then lgrp:=2 else lgrp:=1;
  544. inc(count);
  545. end;
  546.  
  547. end;
  548.  
  549. wri:
  550. if gc[1]>=k then
  551. begin
  552. for i:=1 to k do write(g1[i,1],' ');
  553. end else
  554. begin
  555. if gc[2]>=k then
  556. begin
  557. for i:=1 to k do write(g1[i,2],' ');
  558. end else
  559. begin
  560. writeln('0');
  561. end;
  562. end;
  563. close(input);
  564. close(output);
  565. end;
  566. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement