Guest User

Untitled

a guest
Jan 3rd, 2018
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int a[10][10];
  7. int x,y;
  8.  
  9. int movevalid(int i,int j,int x)
  10. {
  11. switch(x)
  12. {
  13. case 1: if(a[i+1][j]==-1)
  14. return 0;
  15. else if(a[i+2][j]==-1)
  16. return 0;
  17. break;
  18. case 2: if(a[i-1][j]==-1)
  19. return 0;
  20. else if(a[i-2][j]==-1)
  21. return 0;
  22. break;
  23. case 3: if(a[i][j+1]==-1)
  24. return 0;
  25. else if(a[i][j+2]==-1)
  26. return 0;
  27. break;
  28. case 4: if(a[i][j-1]==-1)
  29. return 0;
  30. else if(a[i][j-2]==-1)
  31. return 0;
  32. break;
  33. }
  34. return 1;
  35. }
  36.  
  37. void visit(int r,int c)
  38. {
  39. if(r>=x||r<0||c>=y||c<0)
  40. {
  41.  
  42. }
  43. else if(a[r][c]==-1)
  44. {
  45.  
  46. }
  47. else if(a[r][c]==0)
  48. {
  49. // cout<<r<<"\t"<<c<<"\n";
  50. }
  51. else
  52. {
  53. a[r][c]=0;
  54. //cout<<r<<"\t"<<c<<"<<<<====\n";
  55. //int k;
  56. if(movevalid(r,c,1)==1)
  57. visit(r+2,c+1);
  58. if(movevalid(r,c,1)==1)
  59. visit(r+2,c-1);
  60. if(movevalid(r,c,2)==1)
  61. visit(r-2,c+1);
  62. if(movevalid(r,c,2)==1)
  63. visit(r-2,c-1);
  64. if(movevalid(r,c,3)==1)
  65. visit(r+1,c+2);
  66. if(movevalid(r,c,4)==1)
  67. visit(r+1,c-2);
  68. if(movevalid(r,c,3)==1)
  69. visit(r-1,c+2);
  70. if(movevalid(r,c,4)==1)
  71. visit(r-1,c-2);
  72. //cout<<"COMPLETED FOR "<<r<<"\t"<<c<<"\n";
  73. // return k;
  74. }
  75. }
  76.  
  77. int main()
  78. {
  79. cin>>x;
  80. int i,j,k;
  81.  
  82. for(i=0;i<10;i++)
  83. {
  84. for(j=0;j<10;j++)
  85. a[i][j]=-1;
  86. }
  87. for(i=0;i<x;i++)
  88. {
  89. cin>>j>>k;
  90. while(k>0)
  91. {
  92. a[i][j+k-1]=1;
  93. k--;
  94. }
  95. }
  96. y=0;
  97. for(j=0;j<10;j++)
  98. {
  99. for(i=0;i<x;i++)
  100. {
  101. if(a[i][j]==1&&j>y)
  102. {
  103. y=j;
  104. break;
  105. }
  106.  
  107. }
  108. }
  109. /*for(i=0;i<10;i++)
  110. {
  111. for(j=0;j<10;j++)
  112. cout<<a[i][j]<<"\t";
  113. cout<<"\n";
  114. }*/
  115. // cout<<"\n\n\n";
  116. y++;
  117. // cout<<x<<" "<<y<<"\n\n\n";
  118. //cout<<y<<"\n";
  119. visit(0,0);
  120. int count=0;
  121. for(i=0;i<10;i++)
  122. {
  123. for(j=0;j<10;j++)
  124. {
  125. if(a[i][j]==1)
  126. count++;
  127. }
  128. }
  129. cout<<count;
  130. }
RAW Paste Data Copied