Advertisement
neronv2

Algorithm1

Mar 21st, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     ifstream cin("input.txt");
  7.     ofstream cout("output.txt");
  8.     int _new[50],_old[50],a[100][100],chek[100];
  9.     int n,count = 0;;
  10.    
  11.     cin >> n;
  12.    
  13.     for (int i=0; i<10;i++)
  14.         chek[i] = 0;
  15.     _old[0] = 1;
  16.     _old[1] = 1;
  17.     for (int i=1; i<=n;i++){
  18.         for (int j = 1; j<=n; j++)
  19.             cin >> a[i][j];
  20.     }
  21.     chek[1] = 1;
  22.    
  23.     while (1){
  24.         for (int i=1; i <= _old[0]; i++){
  25.            
  26.             for (int j=_old[i]; j <= n; j++){
  27.             //  cout << "!" << a[_old[i]][j] << endl;
  28.                
  29.                 if ((a[_old[i]][j] == 1) && (chek[j] == 0)){
  30.                     //cout << "!!!!!!!!!!!"<< endl;
  31.                
  32.                     chek[j] = 1;
  33.                
  34.                     _new[0]++;
  35.                
  36.                     _new[_new[0]] = j;
  37.                        
  38.                 }
  39.                
  40.             }
  41.        
  42.         cout << "!!!" << _new[0] << endl;
  43.         for (int t = 0; t <= _new[0];t++)
  44.             cout << _new[t] << " ";
  45.         cout << endl;
  46.            
  47.         }
  48.        
  49.         for (int t = 0; t <= _new[0];t++)
  50.             _old[t] = _new[t];
  51.         _new[0] = 0;
  52.         count++;
  53.         if (chek[8] == 1) break;
  54.        
  55.        
  56.     }
  57.     cout << count;
  58.    
  59.    
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement