Advertisement
Guest User

Untitled

a guest
May 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <fstream>
  2. #include <cmath>
  3. #define N 1001
  4. using namespace std;
  5.  
  6. ifstream cin("dame.in");
  7. ofstream cout("dame.out");
  8. int n, k = 1, st[N], t;
  9. bool as, ev;
  10.  
  11. int main() {
  12. cin >> n;
  13. if(n == 1)
  14. cout << "1 sol";
  15. else
  16. if(n <= 3)
  17. cout << "Nu-s";
  18. else {
  19. st[k] = 0;
  20. k = 1;
  21.  
  22. while(k > 0) {
  23. do {
  24. if(st[k] < n) {
  25. st[k] = st[k] + 1;
  26. as = 1;
  27. }
  28. else
  29. as = 0;
  30.  
  31. if(as)
  32. ev = 1;
  33.  
  34. for(int i = 1; i < k; i++)
  35. if(st[k] == st[i] || abs(st[k] - st[i]) == abs(k - i))
  36. ev = 0;
  37. } while(!as || as && ev);
  38. }
  39.  
  40. if(as)
  41. if(k == n) {
  42. for(int i = 1; i <= n; i++)
  43. cout << st[i] << ' ';
  44. t++;
  45. cout << '\n';
  46. }
  47. else {
  48. k++;
  49. st[k] = 0;
  50. }
  51. else
  52. k--;
  53. cout << t << "solutii";
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement