ch1 : Checker Challenge


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.   NAME : Nursoltan
  3.   PROB : checker
  4.   LANG : C++
  5.   DATE : 03/07/11 20:40
  6. */
  7. #include <algorithm>
  8. #include <bitset>
  9. #include <cctype>
  10. #include <cmath>
  11. #include <cstdio>
  12. #include <cstdlib>
  13. #include <cstring>
  14. #include <ctime>
  15. #include <sstream>
  16. #include <iostream>
  17. #include <map>
  18. #include <set>
  19. #include <stack>
  20. #include <utility>
  21. #include <queue>
  22.  
  23. using namespace std;
  24.  
  25. #define MAX 100
  26. #define INF INT_MAX
  27. #define eps (1e-9)
  28.  
  29. #define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++)
  30. #define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--)
  31. #define CLR(_x) memset((_x),0,sizeof(_x))
  32. #define SQR(_x) ((_x)*(_x))
  33. #define all(_x) _x.begin(),_x.end()
  34. #define sz(_x) sizeof(_x)
  35.  
  36. #define vc vector<int>
  37. #define pb push_back
  38. #define mp make_pair
  39. #define iss istringstream
  40. #define oss ostringstream
  41. #define px first
  42. #define py second
  43.  
  44. typedef long long ll;
  45. typedef pair <int,int> point;
  46. int ABS(int _x){ return _x>0?_x:-_x; }
  47.  
  48. int N,shiid[20],cnt;
  49. int VIS,RDIA,LDIA;
  50.  
  51. void rec(int row){
  52. if(row==N){
  53. if(cnt<3){
  54. FOR(i,0,N){ if(i>0) cout<<" "; cout<<shiid[i]+1; }
  55. cout<<endl;
  56. }
  57. cnt++;
  58. }
  59. else
  60. FOR(col,0,N)
  61. if(!(VIS & 1<<col) && !(RDIA & 1<<(col-row+N)) && !(LDIA & 1<<(col+row))){
  62. VIS|=1<<col;
  63. RDIA|=1<<(col-row+N);
  64. LDIA|=1<<(col+row);
  65. shiid[row]=col;
  66. rec(row+1);
  67. VIS&=~(1<<col);
  68. RDIA&=~(1<<(col-row+N));
  69. LDIA&=~(1<<(col+row));
  70. }
  71. }
  72.  
  73. int main()
  74. {
  75. freopen("checker.in","r",stdin);
  76. freopen("checker.out","w",stdout);
  77.  
  78. cin>>N;
  79. rec(0);
  80. cout<<cnt<<endl;
  81.  
  82. //system("pause");
  83. return 0;
  84. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.