Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tavy;
- /**
- *
- * @author Student
- */
- public class Tavy {
- static final int N=6;
- // pocet tiav
- static int [][]d=new int[N+1][N+1];
- //poradia v jednotlivych dnoch
- static boolean[][] naucitSa=new boolean[N+1][N+1];
- // naucita sa [i][j]==true=> tava j sa ma naucit znacku i
- static int pocetRieseni=0;
- static void vypisRiesenie(){
- for(int i=1;i<d.length;i++){
- for(int j=1;j<d.length;j++){
- System.out.print(d[i][j]);
- }
- System.out.println();
- }
- for(int i=1;i<naucitSa.length;i++){
- for(int j=1;j<naucitSa.length;j++){
- System.out.print(naucitSa[i][j]+";");
- }
- System.out.println();
- }
- }
- public static void postavTavu(int den,int miesto){
- for(int t=1; t<=N; t++){
- if(!pochoduje(t) && naucitSa[d[den][miesto-1]][t]
- /*tava t v tento den nepochoduje a este sa neucila znacku svojej
- predchodkine */){
- //tavu t umiestnime na tuto poziciu
- d[den][miesto] = t;
- naucitSa[d[den][miesto-1]][t]=false;
- if(den==N && miesto==N){
- pocetRieseni++;
- vypisRiesenie(pocetRieseni);
- }else if (miesto==N){
- postavTavu(den+1, 2);
- }else{
- postavTavu(den, miesto+1);
- }
- // zrusit posledny krok (uvolnit policko)
- d[den][miesto]=0;
- naucitSa[d[den][miesto-1]][t]=true;
- }
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // inicializacia poli d a naucitSa
- for(int i=1;i<=N;i++){
- for(int j=1;j<=N;j++){
- naucitSa[i][j]=true;
- }
- }
- d[1][1]=1;
- for(int i=2;i<=N;i++){
- d[i][1]=i;
- d[1][i]=i;
- naucitSa[i-1][i]=false;
- }
- postavTavu(2,2);
- vypisRiesenie();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement