Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <math.h>
  5. #include <string>
  6. #include <set>
  7. #include <cstdio>
  8. #include <iomanip>
  9. #include <map>
  10. #include <stdio.h>
  11. #include <math.h>
  12. #include<queue>
  13. #define PI acos(-1.0)
  14. using namespace std;
  15. const long long inf = 10000000000;
  16. vector<vector<double > > table(5, vector<double>(5));
  17. int n;
  18. void input() {
  19. cin >> n;
  20. double cnt;
  21. for (int i = 0; i < n; i++) {
  22. for (int j = 0; j < n; j++) {
  23. cin >> cnt;
  24. table[i][j] = cnt;
  25. }
  26. }
  27. }
  28. void solve() {
  29. bool used[4];
  30. for (int i = 0; i < 4; i++) {
  31. used[i] = false;
  32. }
  33.  
  34. for (int i = 0; i < n; i++) {
  35. vector <int> ans;
  36. double mult = 1;
  37. int first = i;
  38. int last = i;
  39.  
  40. int now = rand() % n;
  41.  
  42. for (int k = 0; k < 10000; k++) {
  43. while (used[now]) {
  44. int now = rand() % n;
  45. }
  46. mult *= table[last][now];
  47. last = now;
  48.  
  49. ans.push_back(last + 1);
  50.  
  51. if (now == first) {
  52. if (mult > 1) {
  53. cout << "YES" << "\n";
  54. for (int m = 0; m < ans.size(); m++) {
  55. cout << ans[m] << " ";
  56. }
  57. return;
  58. }
  59. else if (mult == 1) {
  60. ans.clear();
  61. mult = 1;
  62.  
  63. for (int i = 0; i < 4; i++) {
  64. used[i] = false;
  65. }
  66. }
  67. else {
  68. cout << "YES" << "\n";
  69. for (int m = ans.size() - 1; m >= 0; m--) {
  70. cout << ans[m] << " ";
  71. }
  72. return;
  73. }
  74.  
  75. }
  76. }
  77.  
  78. }
  79. cout << "NO";
  80. }
  81. int main() {
  82. input();
  83. solve();
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement