Advertisement
Guest User

Untitled

a guest
May 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp3
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[,] board=new int[10,10];
  14. n_queens(board, 4, 2);
  15. }
  16. public static void n_queens(int[,] board, int size, int solution_num)
  17. {
  18. int temp;
  19. int[] malkot = new int[size];
  20. for (int k = 0; k < size; k++)
  21. {
  22. malkot[k] = -1;
  23. }
  24. for (int i = 0; i < size; i++)
  25. {
  26. temp = PutMeMalkot(malkot, size, 0, 0, i);
  27. if (temp != -4)
  28. {
  29. malkot[i] = temp;
  30. }
  31. else
  32. {
  33. temp = ChnageAllThePastMalkot(malkot, i, size, i);
  34. if (temp == -6)
  35. {
  36. Console.WriteLine("אין פיתרון");
  37. }
  38. else
  39. {
  40. i = temp;
  41. }
  42. }
  43. }
  44. Console.WriteLine("asdasd");
  45. }
  46. public static int ChnageAllThePastMalkot(int[] malkot, int Row,int size,int witchRow)
  47. {
  48. if (malkot[Row]+1 < size-1)
  49. {
  50. if (malkot[Row - 1] + 1 > size)
  51. {
  52. malkot[Row - 1] = -1;
  53. return ChnageAllThePastMalkot(malkot, Row - 1, size, witchRow);
  54. }
  55. else
  56. {
  57. int temp = PutMeMalkot(malkot, size, 0, malkot[Row - 1] + 1, Row - 1);
  58. if (temp == -4)
  59. {
  60. malkot[Row - 1] = -1;
  61. return ChnageAllThePastMalkot(malkot, Row - 1, size, witchRow);
  62. }
  63. else
  64. {
  65. malkot[Row - 1] = temp;
  66. return Row - 1;
  67. }
  68. }
  69. }
  70. else
  71. {
  72. malkot[witchRow] = -6;
  73. return -6;
  74. }
  75. }
  76. public static int PutMeMalkot(int[] malkot, int size,int row,int place,int WhatRow)
  77. {
  78. if (place > size-1)
  79. {
  80. return -4;
  81. }
  82. if (row < size-1 && WhatRow != 0 && row != WhatRow)
  83. {
  84. if (malkot[row] != place
  85. && (malkot[row] + (1 * (WhatRow - row)) != place)
  86. && (malkot[row] - (1 * (WhatRow - row)) != place))
  87. {
  88. return PutMeMalkot(malkot, size, row + 1, place, WhatRow);
  89. }
  90. else
  91. {
  92. return PutMeMalkot(malkot, size, 0, place + 1, WhatRow);
  93. }
  94. }
  95. else
  96. {
  97. return place;
  98. }
  99. return -2;
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement