Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1.  
  2. #define _CRT_SECURE_NO_WARNINGS
  3.  
  4.  
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <queue>
  8. #include <cstdio>
  9. #include <vector>
  10. #include <deque>
  11. #include <map>
  12. #include <set>
  13. #include <string>
  14. #include <deque>
  15. #include <cmath>
  16. #include <stack>
  17. #include <unordered_map>
  18. #include <cstring>
  19.  
  20.  
  21. #define mp make_pair
  22.  
  23.  
  24. using namespace std;
  25.  
  26. typedef long long ll;
  27. typedef long double ld;
  28.  
  29. const ll inf = (long long)1e18;
  30. const ll mod = 1000 * 1000 * 1000 + 7;
  31. const int num = 1000 * 1000 + 7;
  32. const int N = 150000 + 7;
  33. const long double PI = acos(-1.0);
  34.  
  35.  
  36. struct input {
  37. int n, m;
  38. int a[50][50];
  39. void read() {
  40. cin >> n >> m;
  41. for (int i = 1; i <= n; ++i)
  42. for (int j = 1; j <= m; ++j)
  43. cin >> a[i][j];
  44. }
  45.  
  46. }ba;
  47. int syun[50], hor[50];
  48. int msyun[50], mhor[50];
  49. int a[50][50];
  50. int n, m;
  51. void get() {
  52. ba.read();
  53. n = ba.n;
  54. m = ba.m;
  55. for (int i = 1; i <= n; ++i)
  56. for (int j = 1; j <= m; ++j)
  57. a[i][j] = ba.a[i][j];
  58. }
  59.  
  60. void clear() {
  61. memset(syun, 0, sizeof(syun));
  62. memset(hor, 0, sizeof(hor));
  63. memset(msyun, 0, sizeof(msyun));
  64. memset(mhor, 0, sizeof(mhor));
  65. }
  66. void write() {
  67. for (int i = 1; i <= n; ++i) {
  68. for (int j = 1; j < m; ++j) {
  69. cout << a[i][j] << " ";
  70. }
  71. cout << a[i][m] << endl;
  72. }
  73. }
  74. int main() {
  75. get();
  76. while (true) {
  77. clear();
  78. pair<pair<int,pair<int,int>>, pair<int, int>> as = mp(mp(-10000,mp(-10000,-10000)),mp( 0,0));
  79. for (int i = 1; i <= n; ++i)
  80. for (int j = 1; j <= m; ++j) {
  81. syun[i] += a[i][j];
  82. hor[j] += a[i][j];
  83. if (a[i][j] == -1) {
  84. mhor[j]++;
  85. msyun[i]++;
  86. }
  87. }
  88. for (int i = 1; i <= n; ++i)
  89. for (int j = 1; j <= m; ++j) {
  90. if (a[i][j] == 1) {
  91. if (as.first.first < min(syun[i], hor[j]))
  92. as = mp(mp(min(syun[i], hor[j]),mp(max(msyun[i],mhor[j]),min(msyun[i], mhor[j]))),mp(i, j));
  93. else if (as.first.first == min(syun[i], hor[j])) {
  94. if (as.first.second.first>max(msyun[i],mhor[j]))
  95. as = mp(mp(min(syun[i], hor[j]), mp(max(msyun[i], mhor[j]), min(msyun[i], mhor[j]))), mp(i, j));
  96. else if(as.first.second.first==max(msyun[i], mhor[j])) {
  97. if (as.first.second.second >min(msyun[i],mhor[j]))
  98. as = mp(mp(min(syun[i], hor[j]), mp(max(msyun[i], mhor[j]), min(msyun[i], mhor[j]))), mp(i, j));
  99.  
  100. }
  101. }
  102. }
  103. }
  104. if (as.first.first >= 1) {
  105. a[as.second.first][as.second.second] = -1;
  106. }
  107. else {
  108. write();
  109. break;
  110. }
  111. }
  112. return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement