Advertisement
a53

PR_957_1223

a53
Dec 8th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. Zana (957)
  2. ==================================================
  3. #include <fstream>
  4. #define nmax 105
  5. #define mmax 105
  6. using namespace std;
  7.  
  8. ifstream f("zana.in");
  9. ofstream g("zana.out");
  10.  
  11. int a[nmax][mmax], b[nmax][mmax];
  12. int n, m, k, n1=0, n2=0;
  13.  
  14.  
  15. void citire()
  16. {
  17. f >> n >> m >> k;
  18. int i, j, p;
  19. for(p = 1; p <=k; p++)
  20. {
  21. f >> i >> j;
  22. a[i][j] ++;
  23. }
  24. f.close();
  25. }
  26.  
  27. void fill(int i, int j, int v)
  28. {
  29. if(b[i][j]==0)
  30. {
  31. b[i][j]=v;
  32. if(a[i][j]>n1)
  33. {
  34. n1=a[i][j];
  35. n2=1;
  36. }
  37. else
  38. {
  39. if(a[i][j]==n1)
  40. n2++;
  41. }
  42. if(a[i][j]==0)
  43. {
  44. if(a[i][j+1]>=0)
  45. fill(i,j+1,v+1);
  46. if(a[i][j-1]>=0)
  47. fill(i,j-1,v+1);
  48. if(a[i-1][j]>=0)
  49. fill(i-1,j,v+1);
  50. if(a[i+1][j]>=0)
  51. fill(i+1,j,v+1);
  52. }
  53. }
  54. }
  55.  
  56. int main()
  57. {
  58. citire();
  59. int i;
  60. for(i=0;i<=n+1;i++)
  61. a[i][0]=a[i][m+1]=-1;
  62. for(i=0;i<=m+1;i++)
  63. a[0][i]=a[n+1][i]=-1;
  64. for(i=0;i<=n+1;i++)
  65. b[i][0]=b[i][m+1]=-1;
  66. for(i=0;i<=m+1;i++)
  67. b[0][i]=b[n+1][i]=-1;
  68. fill(1,1,1);
  69. g << n1 << endl << n2 << endl;
  70. g.close();
  71. return 0;
  72. }
  73.  
  74. Magic1 (1223)
  75. =============
  76. #include <iostream>
  77. #include <fstream>
  78.  
  79. using namespace std;
  80. ifstream in("magic1.in");
  81. ofstream out("magic1.out");
  82. long long C;
  83. long N,P;
  84.  
  85. int main()
  86. {
  87. long i;
  88. long long nr;
  89. in>>C>>N>>P;
  90.  
  91. N--;
  92. nr=1;
  93. while(N!=0){
  94. if(N%2==1)
  95. {
  96. nr=(nr*C)%P;
  97. if(nr==0)
  98. nr=P;
  99. }
  100. C=(C*C)%P;
  101. if(C==0)
  102. C=P;
  103. N/=2;
  104. }
  105. out<<nr;
  106.  
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement