Advertisement
Tranvick

Z-4

Sep 22nd, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <queue>
  5.  
  6. using namespace std;
  7.  
  8. const int N = 1111;
  9. int n;
  10. double a[N][N];
  11.  
  12. bool calc() {
  13.     bool ok = 0;
  14.     for (int k = 0; k < n; ++k)
  15.         for (int i = 0; i < n; ++i)
  16.             for (int j = 0; j < n; ++j)
  17.                 if (a[i][k] * a[k][j] > a[i][j]) {
  18.                     ok = 1;
  19.                     a[i][j] = a[i][k] * a[k][j];
  20.                 }
  21.     for (int i = 0; i < n && ok; ++i)
  22.         if (a[i][i] > 1) ok = 0;
  23.     return ok;
  24. }
  25.  
  26. int main(){            
  27.     ifstream fin("in.txt");
  28.     ofstream fout("out.txt");
  29.     fin >> n;
  30.     for (int i = 0; i < n; ++i)
  31.         for (int j = 0; j < n; ++j)
  32.             fin >> a[i][j];
  33.     while (calc());
  34.     for (int i = 0; i < n; ++i)
  35.         if (a[i][i] > 1) {
  36.             fout << "yes";
  37.             return 0;
  38.         }
  39.     fout << "no";
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement