Advertisement
palmerstone

N_Queen

Oct 7th, 2012
1,287
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ios>
  2. #include <new>
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <cctype>
  7. #include <cstdlib>
  8. #include <climits>
  9. #include <ctime>
  10. #include <assert.h>
  11. #include <istream>
  12. #include <ostream>
  13. #include <iostream>
  14. #include <iomanip>
  15. #include <algorithm>
  16. #include <vector>
  17. #include <string>
  18. #include <numeric>
  19. #include <fstream>
  20. #include <sstream>
  21. #include <map>
  22. #include <set>
  23. #include <list>
  24. #include <stack>
  25. #include <queue>
  26. #include <deque>
  27. #include <locale>
  28. #include <memory>
  29. #include <valarray>
  30. #include <complex>
  31. #include <limits>
  32. #include <bitset>
  33. #include <iterator>
  34. #include <utility>
  35. #include <exception>
  36. #include <functional>
  37. #include <streambuf>
  38. #include <typeinfo>
  39. #include <cxxabi.h>
  40. #include <tr1/cstdio>
  41. #include <tr1/cstdlib>
  42. #include <tr1/cmath>
  43. #include <tr1/climits>
  44. #include <tr1/cfenv>
  45. #include <tr1/cstdarg>
  46. #include <tr1/ctgmath>
  47. #include <tr1/cstdbool>
  48. #include <tr1/ctime>
  49. #include <tr1/cstdint>
  50. #include <tr1/cwchar>
  51. #include <tr1/cwctype>
  52. #include <tr1/cinttypes>
  53. #include <ext/algorithm>
  54. #include <ext/functional>
  55. #include <ext/new_allocator.h>
  56. #include <ext/pod_char_traits.h>
  57. #include <ext/vstring.h>
  58. #include <ext/stdio_filebuf.h>
  59. #include <ext/atomicity.h>
  60. #include <ext/concurrence.h>
  61. #include <ext/iterator>
  62. #include <ext/numeric>
  63. #include <ext/stdio_sync_filebuf.h>
  64. #include <ext/pool_allocator.h>
  65. #include <ext/array_allocator.h>
  66. #include <ext/debug_allocator.h>
  67. #include <ext/malloc_allocator.h>
  68. #include <ext/throw_allocator.h>
  69. #include <ext/bitmap_allocator.h>
  70. #include <ext/enc_filebuf.h>
  71. #include <ext/memory>
  72. #include <ext/rope>
  73. #include <ext/typelist.h>
  74. #include <ext/mt_allocator.h>
  75. #include <ext/slist>
  76. #include <ext/type_traits.h>
  77. #include <debug/bitset>
  78. #include <debug/string>
  79. #include <debug/deque>
  80. #include <debug/set>
  81. #include <debug/map>
  82. #include <debug/list>
  83. #include <debug/vector>
  84. #include <tr1/functional>
  85. #include <tr1/array>
  86. #include <tr1/memory>
  87. #include <tr1/tuple>
  88. #include <tr1/utility>
  89. #include <tr1/type_traits>
  90. #include <tr1/regex>
  91. #include <tr1/random>
  92. #include <tr1/unordered_set>
  93. #include <tr1/unordered_map>
  94. #include <ext/rb_tree>
  95. #include <ext/numeric_traits.h>
  96. #include <ext/codecvt_specializations.h>
  97.  
  98. #define vinf (1 << 28)
  99. #define inf ((~0U) >> (1))
  100. #define pi (2.0 * acos(0.0))
  101. #define lowbit(x) ((x) & (-(x)))
  102. #define sine(x) (sin(radians(x)))
  103. #define cosine(x) (cos(radians(x)))
  104. #define tangent(x) (tan(radians(x)))
  105. #define arcsine(x) (degrees((asin(x))))
  106. #define arccosine(x) (degrees((acos(x))))
  107. #define arctangent(x) (degrees((atan(x))))
  108. #define clr(ar) (memset(ar, 0, sizeof(ar)))
  109. #define radians(x) (((1.0 * x * pi) / 180.0))
  110. #define degrees(x) (((x * 180.0) / (1.0 * pi)))
  111. #define read() (freopen("lol.txt", "r+", stdin))
  112. #define out() (freopen("out.txt", "w+", stdout))
  113. #define write() (freopen("lol.txt", "w+", stdout))
  114. #define dbg(x) (std::cout << #x << " = " << x << endl)
  115. #define twopow(x) ((((x & (x - 1)) == 0) && (x != 0)) ? (true) : (false))
  116. #define mod(n, m) ((n >= 0) ? (n % m) : ((abs(n) % m) == 0) ? 0 : (m - (abs(n) % m)))
  117.  
  118. using namespace std;
  119.  
  120. typedef uint32_t uint;
  121. uint lim, n, counter;
  122.  
  123. void bitmask(uint d, uint c, uint l, uint r){
  124.     uint b, a, s;
  125.     if (!d){
  126.         counter++;
  127.         return;
  128.     }
  129.  
  130.     a = (c | (l <<= 1) | (r >>= 1)) & lim;
  131.     if (a != lim){
  132.         --d;
  133.         for (b = 1; b <= lim; b <<= 1){
  134.             if (!(b & a)) bitmask(d, b | c, b | l, b | r);
  135.         }
  136.     }
  137. }
  138.  
  139. int main(){
  140.     //while (scanf("%hu", &n)){
  141.     n = 14;
  142.         counter = 0;
  143.         lim = (1U << n) - 1;
  144.  
  145.         bitmask(n, 0, 0, 0);
  146.         printf("Solutions: %d\n", counter);
  147.     //}
  148.     return 0;
  149. }
Advertisement
RAW Paste Data Copied
Advertisement