fork(37) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int c,n,m;
  6. cin>>m>>n>>c;
  7. int matrix[c+1][n+1][m+1]; // x,y,z such that xth 2D matrix represnt xth character
  8. for(int i=1;i<=c;i++)
  9. {
  10. for(int j=1;j<=m;j++)
  11. {
  12. for(int k=1;k<=n;k++)
  13. {
  14. cin>>matrix[i][j][k];
  15. }
  16. }
  17. }
  18. bool compared[100][100] = {0};
  19. vector<set<pair<int,int>>> V;
  20. for(int i=1;i<=c;i++)
  21. {
  22. for(int j=1;j<=c;j++)
  23. {
  24. if(i!=j && !compared[i][j] && !compared[j][i])
  25. {
  26. set<pair<int,int>> S;
  27. compared[i][j] = compared[j][i] = 1;
  28. for(int x=1;x<=m;x++)
  29. {
  30. for(int y=1;y<=n;y++)
  31. {
  32. if(matrix[i][x][y] != matrix[j][x][y])
  33. {
  34. S.insert(make_pair(x,y));
  35. }
  36. }
  37. }
  38. V.push_back(S);
  39. }
  40. }
  41. }
  42. map<pair<int,int>,int> M; // for keeping record that a point x,y exists in how many comparisions
  43. bool included[100];
  44. memset(included,0,sizeof(included));
  45. bool done = 0;
  46. int ans = 0;
  47. while(!done)
  48. {
  49. for(int i=0;i<V.size();i++)
  50. {
  51. if(!included[i])
  52. for(auto it = V[i].begin();it!=V[i].end();it++)
  53. {
  54. M[*it]++;
  55. }
  56. }
  57. int maxi = 0;
  58. pair<int,int> P;
  59. for(auto it = M.begin() ; it!=M.end() ; it++)
  60. {
  61. if(it->second > maxi)
  62. {
  63. P = it->first;
  64. maxi = it->second;
  65. }
  66. }
  67. for(int i=0;i<V.size();i++)
  68. {
  69. if(!included[i] && V[i].find(P)!=V[i].end())
  70. {
  71. included[i] = 1;
  72. V[i].erase(P);
  73. }
  74. }
  75. ans++;
  76. int i;
  77. for(i=0;i<V.size();i++)
  78. {
  79. if(!included[i])
  80. {
  81. break;
  82. }
  83. }
  84. if(i==V.size())
  85. {
  86. done = 1;
  87. }
  88. M.clear();
  89. }
  90. cout<<ans<<endl;
  91. return 0;
  92. }
  93.  
Success #stdin #stdout 0s 3480KB
stdin
Standard input is empty
stdout
1