Advertisement
a53

VeciniBuni_50p

a53
Mar 2nd, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream f("vecini_buni.in");
  4. ofstream g("vecini_buni.out");
  5. char a[3][1002];
  6.  
  7. int main()
  8. {
  9. int m,n,k,i,j,x,y,maxim=0,nrvec,nr=0;
  10. int dl[]={-1,-1,0,1,1, 1, 0,-1}; /// vector de directie pentru linie
  11. int dc[]={ 0, 1,1,1,0,-1,-1,-1}; /// vector de directie pentru coloana
  12. f>>m>>n>>k; /// m=nr. linii; n=nr. coloane; k=nr. perechi (i,j) egale cu 1
  13. for(int i=0;i<3;++i)
  14. a[i][0]=a[i][n+1]=2;
  15. for(int j=1;j<=n;++j)
  16. a[0][j]=a[2][j]=2;
  17. int linie=1;
  18. f>>x>>y;
  19. if(x==1)
  20. {
  21. a[1][y]=1;
  22. while(f>>x>>y&&x==1)
  23. a[1][y]=1;
  24. }
  25. while(linie<m+1)
  26. {
  27. ++linie;
  28. if(x==linie)
  29. {
  30. a[2][y]=1;
  31. while(f>>x>>y&&x==linie)
  32. a[2][y]=1;
  33. }
  34. else
  35. for(int j=1;j<=n;++j)
  36. if(linie==m+1)
  37. a[2][j]=2;
  38. else
  39. a[2][j]=0;
  40.  
  41. for(j=1;j<=n;++j)
  42. {
  43. nrvec=0;
  44. for(k=0;k<8;++k) /// un punct are 8 vecini
  45. {
  46. int ii=1+dl[k]; ///calculez coordonatele noului punct
  47. int jj=j+dc[k];
  48. if(a[1][j]==a[ii][jj])
  49. ++nrvec;
  50. }
  51. if(nrvec>maxim)
  52. maxim=nrvec,nr=1;
  53. else
  54. if(nrvec==maxim)
  55. ++nr;
  56. }
  57. for(i=0;i<=1;++i)
  58. for(j=0;j<=n+1;++j)
  59. a[i][j]=a[i+1][j];
  60. for(j=1;j<=n;++j)
  61. a[2][j]=0;
  62. }
  63. g<<maxim<<' '<<nr;
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement