Advertisement
a53

Vecini Buni 100p

a53
Mar 3rd, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream f("vecini_buni.in");
  4. ofstream g("vecini_buni.out");
  5. short 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. for(j=1;j<=n;++j)
  29. a[2][j]=0;
  30. if(x==linie)
  31. {
  32. a[2][y]=1;
  33. while(f>>x>>y&&x==linie)
  34. a[2][y]=1;
  35. }
  36. else
  37. for(int j=1;j<=n;++j)
  38. a[2][j]=0;
  39. if(linie==m+1)
  40. for(int j=1;j<=n;++j)
  41. a[2][j]=2;
  42. for(j=1;j<=n;++j)
  43. {
  44. nrvec=0;
  45. for(k=0;k<8;++k) /// un punct are 8 vecini
  46. {
  47. int ii=1+dl[k]; ///calculez coordonatele noului punct
  48. int jj=j+dc[k];
  49. if(a[1][j]==a[ii][jj])
  50. ++nrvec;
  51. }
  52. if(nrvec>maxim)
  53. maxim=nrvec,nr=1;
  54. else
  55. if(nrvec==maxim)
  56. ++nr;
  57. }
  58. for(i=0;i<=1;++i)
  59. for(j=0;j<=n+1;++j)
  60. a[i][j]=a[i+1][j];
  61. }
  62. g<<maxim<<' '<<nr;
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement