1.5.4 Checker Challenge
2013-08-22 11:52
204 查看
Checker Challenge
Examine the 6x6 checkerboard below and note that the six checkers are arranged on the board so that one and only one is placed in each row and each column, and there is never more than one in any diagonal. (Diagonals run from southeast to northwest and southwest to northeast and include all diagonals, not just the major two.)Column 1 2 3 4 5 6 ------------------------- 1 | | O | | | | | ------------------------- 2 | | | | O | | | ------------------------- 3 | | | | | | O | ------------------------- 4 | O | | | | | | ------------------------- 5 | | | O | | | | ------------------------- 6 | | | | | O | | -------------------------
The solution shown above is described by the sequence 2 4 6 1 3 5, which gives the column positions of the checkers for each row from 1 to 6:
ROW | 1 | 2 | 3 | 4 | 5 | 6 |
COLUMN | 2 | 4 | 6 | 1 | 3 | 5 |
Special note: the larger values of N require your program to be especially efficient. Do not precalculate the value and print it (or even find a formula for it); that's cheating. Work on your program until it can solve the problem properly. If you insist on cheating, your login to the USACO training pages will be removed and you will be disqualified from all USACO competitions. YOU HAVE BEEN WARNED.
TIME LIMIT: 1 CPU second
PROGRAM NAME: checker
INPUT FORMAT
A single line that contains a single integer N (6 <= N <= 13) that is the dimension of the N x N checkerboard.SAMPLE INPUT (file checker.in)
6
OUTPUT FORMAT
The first three lines show the first three solutions found, presented as N numbers with a single space between them. The fourth line shows the total number of solutions found.SAMPLE OUTPUT (file checker.out)
2 4 6 1 3 5 3 6 2 5 1 4 4 1 5 2 6 3 4
{ ID: makeeca1 PROG: checker LANG: PASCAL } program checker; var a:array[0..20]of longint; n,upperlim,sum:longint; procedure test(row,ld,rd,t:longint); var pos,p,i:longint; begin if row<>upperlim then begin pos:=upperlim and not (row or ld or rd); while pos<>0 do begin p:=pos and -pos; a[t]:=p; pos:=pos-p; test(row+p,(ld+p)shl 1,(rd+p)shr 1,t+1); end; end else begin inc(sum); if sum<=3 then begin for i:=0 to n-2 do write(round((ln(a[i])/ln(2)))+1,' ');//use round,not trunc!!! writeln(round(ln(a[n-1])/ln(2))+1); end; end; end; begin assign(input,'checker.in');reset(input); assign(output,'checker.out');rewrite(output); readln(n); upperlim:=(1 shl n)-1; test(0,0,0,0); writeln(sum); close(input);close(output); end.
相关文章推荐
- USACO 1.5.4 Checker Challenge 题解
- USACO 1.5.4 Checker Challenge
- There are 常数s 和 常数s! Usaco 1.5.4 Checker Challenge
- USACO section 1.5.4 Checker Challenge
- USACO section 1.5.4 Checker Challenge
- usaco 1.5.4 Checker Challenge
- USACO1.5.4 checker challenge
- [USACO 1.5.4] Checker Challenge
- USACO1.5.4 checker challenge
- USACO 1.5.4 Checker Challenge ———— DFS
- usaco 1.5.4——checker
- USACO-cha1-sec1.5 Checker Challenge
- Checker Challenge
- Checker Challenge
- USACO Section 1.5 Checker Challenge(八皇后问题)
- USACO 1.4 Checker Challenge 位运算
- USACO1.5 Checker Challenge(类n皇后问题)
- USACO 6.5.5 Checker Challenge 回溯
- USACO 1.5 Checker Challenge(DFS)
- USACO Section 1.5 Checker Challenge