Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. package tavy;
  2.  
  3. /**
  4.  *
  5.  * @author Student
  6.  */
  7. public class Tavy {
  8.     static final int N=6;
  9. // pocet tiav
  10.     static int [][]d=new int[N+1][N+1];
  11. //poradia v jednotlivych dnoch
  12.     static boolean[][] naucitSa=new boolean[N+1][N+1];
  13. // naucita sa [i][j]==true=> tava j sa ma naucit znacku i
  14.     static int pocetRieseni=0;
  15.    
  16.  
  17.     static void vypisRiesenie(){
  18.        
  19.       for(int i=1;i<d.length;i++){
  20.             for(int j=1;j<d.length;j++){
  21.                 System.out.print(d[i][j]);
  22.                
  23.             }
  24.             System.out.println();
  25.         }
  26.         for(int i=1;i<naucitSa.length;i++){
  27.             for(int j=1;j<naucitSa.length;j++){
  28.                 System.out.print(naucitSa[i][j]+";");
  29.                
  30.             }
  31.             System.out.println();
  32.         }
  33.        
  34.     }
  35.     public static void postavTavu(int den,int miesto){
  36.        
  37.         for(int t=1; t<=N; t++){
  38.            
  39.             if(!pochoduje(t) && naucitSa[d[den][miesto-1]][t]
  40.                     /*tava t v tento den nepochoduje a este sa neucila znacku svojej
  41.                     predchodkine */){
  42.                 //tavu t umiestnime na tuto poziciu
  43.                 d[den][miesto] = t;
  44.                 naucitSa[d[den][miesto-1]][t]=false;
  45.                
  46.                 if(den==N && miesto==N){
  47.                     pocetRieseni++;
  48.                     vypisRiesenie(pocetRieseni);
  49.                 }else if (miesto==N){
  50.                     postavTavu(den+1, 2);
  51.                 }else{
  52.                     postavTavu(den, miesto+1);
  53.                 }
  54.                 // zrusit posledny krok (uvolnit policko)
  55.                 d[den][miesto]=0;
  56.                 naucitSa[d[den][miesto-1]][t]=true;
  57.             }
  58.         }
  59.     }
  60.     /**
  61.      * @param args the command line arguments
  62.      */
  63.     public static void main(String[] args) {
  64.         // inicializacia poli d a naucitSa
  65.        
  66.        
  67.          
  68.        
  69.        
  70.         for(int i=1;i<=N;i++){
  71.             for(int j=1;j<=N;j++){
  72.                 naucitSa[i][j]=true;
  73.             }
  74.            
  75.           }
  76.        
  77.         d[1][1]=1;
  78.         for(int i=2;i<=N;i++){
  79.            d[i][1]=i;
  80.                 d[1][i]=i;
  81.                 naucitSa[i-1][i]=false;
  82.         }
  83.        
  84.        postavTavu(2,2);
  85.        vypisRiesenie();
  86.        
  87.        
  88.        
  89.        
  90.        
  91.        
  92.        
  93.        
  94.     }
  95.    
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement