Saleh127

Spoj MKJUMPS/Uva live ar 2844

Feb 24th, 2021
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. ll a[12][12];
  6. ll ans=0;
  7.  
  8. bool valid(ll x,ll y)
  9. {
  10. if(x<0 || x>10) return 0;
  11. if(y<0 || y>10) return 0;
  12. if(a[x][y]==0) return 1;
  13. return 0;
  14. }
  15. void lll()
  16. {
  17. ll ss=0;
  18. for(ll i=0; i<11; i++)
  19. {
  20. for(ll j=0; j<11; j++)
  21. {
  22. if(a[i][j]==1) ss++;
  23. }
  24. }
  25. ans=max(ans,ss);
  26. }
  27. void dfs(ll r, ll c)
  28. {
  29.  
  30. lll();
  31.  
  32. if(valid(r-2,c-1))
  33. {
  34. a[r-2][c-1]=1;
  35. dfs(r-2,c-1);
  36. a[r-2][c-1]=0;
  37. }
  38. if(valid(r-2,c+1))
  39. {
  40. a[r-2][c+1]=1;
  41. dfs(r-2,c+1);
  42. a[r-2][c+1]=0;
  43. }
  44. if(valid(r-1,c-2))
  45. {
  46. a[r-1][c-2]=1;
  47. dfs(r-1,c-2);
  48. a[r-1][c-2]=0;
  49. }
  50. if(valid(r-1,c+2))
  51. {
  52. a[r-1][c+2]=1;
  53. dfs(r-1,c+2);
  54. a[r-1][c+2]=0;
  55. }
  56. if(valid(r+1,c-2))
  57. {
  58. a[r+1][c-2]=1;
  59. dfs(r+1,c-2);
  60. a[r+1][c-2]=0;
  61. }
  62. if(valid(r+1,c+2))
  63. {
  64. a[r+1][c+2]=1;
  65. dfs(r+1,c+2);
  66. a[r+1][c+2]=0;
  67. }
  68. if(valid(r+2,c-1))
  69. {
  70. a[r+2][c-1]=1;
  71. dfs(r+2,c-1);
  72. a[r+2][c-1]=0;
  73. }
  74. if(valid(r+2,c+1))
  75. {
  76. a[r+2][c+1]=1;
  77. dfs(r+2,c+1);
  78. a[r+2][c+1]=0;
  79. }
  80.  
  81. }
  82.  
  83.  
  84.  
  85. int main()
  86. {
  87. ios_base::sync_with_stdio(0);
  88. cin.tie(0);
  89. cout.tie(0);
  90.  
  91. ll p,i,j,k,l=1;
  92. while(cin>>p && p)
  93. {
  94. for(i=0; i<11; i++)
  95. {
  96. for(j=0; j<11; j++)
  97. {
  98. a[i][j]=-1;
  99. }
  100. }
  101.  
  102. ll g=0,h;
  103. for(k=0; k<p; k++)
  104. {
  105. ll x,y;
  106. cin>>x>>y;
  107. if(k==0) h=x;
  108. for(i=x; i<(x+y); i++)
  109. {
  110. a[k][i]=0;
  111. g++;
  112. }
  113. }
  114.  
  115. a[0][h]=1;
  116. dfs(0,h);
  117.  
  118.  
  119. j=(g-ans);
  120.  
  121. if(j==1) cout<<"Case "<<l++<<", 1 square can not be reached."<<endl;
  122. else cout<<"Case "<<l++<<", "<<j<<" squares can not be reached."<<endl;
  123.  
  124. j=g=ans=0;
  125. }
  126.  
  127.  
  128. return 0;
  129. }
  130.  
Advertisement
Add Comment
Please, Sign In to add comment