Advertisement
Dorijanko

Untitled

May 17th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. #include "testlib.h"
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. string h[101],h1[101];
  7. bool bio[101][101];
  8. int n,m,k,r,s,se;
  9.  
  10. int dx[]={1,0,-1,0,1,1,-1,-1};
  11. int dy[]={0,1,0,-1,-1,1,1,-1};
  12.  
  13. bool ok(int i,int j)
  14. {
  15. return (i>=0 && j>=0 && i<n && j<m);
  16. }
  17.  
  18. int countKnown()
  19. {
  20. int a=0;
  21. for (int i=0;i<n;++i) for (int j=0;j<m;++j) if (h1[i][j]!='?') ++a;
  22. return a;
  23. }
  24.  
  25. void dfs(int i,int j)
  26. {
  27. if (!ok(i,j)) return;
  28. if (bio[i][j]) return;
  29. if (h[i][j]=='*') return;
  30. bio[i][j]=1;
  31. h1[i][j]=h[i][j];
  32. if (h[i][j]!='0') return;
  33. for (int k=0;k<8;++k) dfs(i+dx[k],j+dy[k]);
  34. }
  35.  
  36. bool close(int i,int j)
  37. {
  38. if (i==r && j==s) return 1;
  39. for (int k=0;k<8;++k) if ((i+dx[k])==r && (j+dy[k])==s) return 1;
  40. return 0;
  41. }
  42.  
  43. int minCount()
  44. {
  45. int mo=0;
  46. for (int i=0;i<n;++i) for (int j=0;j<m;++j) if (h[i][j]=='*') ++mo;
  47. return mo;
  48. }
  49.  
  50. int main(int argc, char **argv){
  51. registerInteraction(argc, argv);
  52. n = inf.readInt(5, 40);
  53. m = inf.readInt(5, 40);
  54. k = inf.readInt(1, n*m/4);
  55. se = inf.readInt();
  56. char **ar=argv;
  57. ar[0][0]=se/256;
  58. ar[0][1]=se%256;
  59. registerGen(argc,ar,1);
  60. cout<<n<<' '<<m<<' '<<k<<endl;
  61. r = ouf.readInt(0,n-1);
  62. s = ouf.readInt(0,m-1);
  63. double lo=0.0001,hi=10000;
  64. bool found=0;
  65. for (int i=0;i<n;++i) for (int j=0;j<m;++j) h[i].push_back('.');
  66. while (!found)
  67. {
  68. double mid=(lo+hi)/2,c=clock();
  69. int su=0,ti=0;
  70. do
  71. {
  72. for (int i=0;i<n;++i) for (int j=0;j<m;++j)
  73. {
  74. if (close(i,j)) continue;
  75. if (rnd.next(1010101)%(int(n*m/sqrt(1+sqrt((i-r)*(i-r)+(j-s)*(j-s)))))<k*mid) h[i][j]='*';
  76. else h[i][j]='.';
  77. }
  78. su+=minCount();
  79. ++ti;
  80. }
  81. while (minCount()!=k && (clock()-c)/CLOCKS_PER_SEC<0.01);
  82. if (minCount()==k) found=1;
  83. if (su*1./ti<k) lo=mid;
  84. else hi=mid;
  85. }
  86. for (int i=0;i<n;++i) for (int j=0;j<m;++j)
  87. {
  88. if (h[i][j]=='*') continue;
  89. int a=0;
  90. for (int k=0;k<8;++k)
  91. {
  92. int i2=i+dx[k],j2=j+dy[k];
  93. if (!ok(i2,j2)) continue;
  94. if (h[i2][j2]=='*') ++a;
  95. }
  96. h[i][j]=a+'0';
  97. }
  98. for (int i=0;i<n;++i) for (int j=0;j<m;++j) h1[i].push_back('?');
  99. dfs(r,s);
  100. bool done=0;
  101. while (!done && countKnown()!=n*m)
  102. {
  103. for (int i=0;i<n;++i) cout<<h1[i]<<endl;
  104. int z=ouf.readInt();
  105. if (z==0) break;
  106. for (int i=0;i<z;++i)
  107. {
  108. int q=ouf.readInt();
  109. int w=ouf.readInt();
  110. ouf.readSpace();
  111. char th=ouf.readChar();
  112. if (th=='*')
  113. {
  114. if (h[q][w]!='*') done=1;
  115. else
  116. {
  117. h1[q][w]=h[q][w];
  118. dfs(q,w);
  119. }
  120. }
  121. else
  122. {
  123. if (h[q][w]=='*') done=1;
  124. else
  125. {
  126. h1[q][w]=h[q][w];
  127. dfs(q,w);
  128. }
  129. }
  130. }
  131. }
  132. cout<<(countKnown()*countKnown()*1.)/(n*m*sqrt(n*m))<<" points, "<<countKnown()<<" found."<<endl;
  133. quitp(_pc((countKnown()*countKnown()*1.)/(n*m*sqrt(n*m)))-16, "%d known things", countKnown());
  134. tout<<(countKnown()*countKnown()*1.)/(n*m*sqrt(n*m))<<endl<<countKnown()<<endl;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement