Md_hosen_zisad

ridwan bai

Oct 3rd, 2017
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,caseno=1;;
  6. cin>> t;
  7. while(t--){
  8. int n;
  9. cin>> n;
  10. vector <int> v[n+5]; //You can use 2D array instead of vector array
  11. for(int a=0;a<n;a++){
  12. for(int b=0;b<n;b++){
  13. int x;
  14. cin>> x;
  15. v[a].push_back(x);
  16. //taking input
  17. //If you use 2D array, just replace with cin>> arr[a][b]
  18. }
  19. }
  20. int cnt=0;
  21. //checking all 2x5 rectangles
  22. for(int a=0;a<n-1;a++){
  23. for(int b=0;b<n-4;b++){
  24. int i=a+2,j=b+5;
  25. vector <int> arr(12,0);
  26. for(int p=a;p<i;p++){
  27. for(int q=b;q<j;q++){
  28. int z=v[p][q];
  29. arr[z]++;
  30. if(arr[z]>1) goto next;
  31. //Each rectangele should have each number from 1 to 10 exactly once.
  32. //If any number from 1 to 10 appears more than once and check next rectangle
  33. //I used goto statement to break two loops at a time.
  34. }
  35. }
  36. cnt++;
  37. next:
  38. i=0;
  39. }
  40. }
  41. //checking all 5x2 rectangles
  42. for(int a=0;a<n-4;a++){
  43. for(int b=0;b<n-1;b++){
  44. int i=a+5,j=b+2;
  45. vector <int> arr(12,0);
  46. for(int p=a;p<i;p++){
  47. for(int q=b;q<j;q++){
  48. int z=v[p][q];
  49. arr[z]++;
  50. if(arr[z]>1) goto next1;
  51. }
  52. }
  53. cnt++;
  54. next1:
  55. i=0;
  56. }
  57. }
  58. //checking all 1x10 rectangles
  59. for(int a=0;a<n;a++){
  60. for(int b=0;b<n-9;b++){
  61. int i=a+1,j=b+10;
  62. vector <int> arr(12,0);
  63. for(int p=a;p<i;p++){
  64. for(int q=b;q<j;q++){
  65. int z=v[p][q];
  66. arr[z]++;
  67. if(arr[z]>1) goto next2;
  68. }
  69. }
  70. cnt++;
  71. next2:
  72. i=0;
  73. }
  74. }
  75. //checking all 10x1 rectangles
  76. for(int a=0;a<n-9;a++){
  77. for(int b=0;b<n;b++){
  78. int i=a+10,j=b+1;
  79. vector <int> arr(12,0);
  80. for(int p=a;p<i;p++){
  81. for(int q=b;q<j;q++){
  82. int z=v[p][q];
  83. arr[z]++;
  84. if(arr[z]>1) goto next3;
  85. }
  86. }
  87. cnt++;
  88. next3:
  89. i=0;
  90. }
  91. }
  92. cout<< "Case " << caseno++ << ": " << cnt <<endl;
  93. }
  94. return 0;
  95. }
Add Comment
Please, Sign In to add comment