Codeforces Round #419 (Div. 2) C.Karen and Game 思维
2017-06-18 18:46
375 查看
传送门
题意:
给你一个矩阵 问你是不是能化为0矩阵。 每次可以使列或者行减少1。 最后输出操作次数并输出过程。
做法:
取列行最小的一个数。 整个列行都减这个数就好啦。判断一下减了多少次((s != cc * n + rr * m))
具体看代码就知道啦。
题意:
给你一个矩阵 问你是不是能化为0矩阵。 每次可以使列或者行减少1。 最后输出操作次数并输出过程。
做法:
取列行最小的一个数。 整个列行都减这个数就好啦。判断一下减了多少次((s != cc * n + rr * m))
具体看代码就知道啦。
#include <iostream> #include <stdio.h> #include <cstring> #include <string> #include <algorithm> #include <queue> #include <stack> #include <cmath> #include <map> #include <bitset> #include <set> #include <vector> #include <functional> using namespace std; const int N = 105; int n, m; int A ; int r , c ; int doRow() { int ans = 0; for (int i = 0; i < n; ++i) { int miv = 1000; for (int j = 0; j < m; ++j) miv = std::min(miv, A[i][j]); r[i]=miv; ans += r[i]; // cout<<ans<<endl; for (int j = 0; j < m; ++j) A[i][j] -= r[i]; } return ans; } int doCol() { int ans = 0; for (int j = 0; j < m; ++j) { int miv = 1000; for (int i = 0; i < n; ++i) miv = std::min(miv, A[i][j]); ans += (c[j] = miv); for (int i = 0; i < n; ++i) A[i][j] -= c[j]; } return ans; } int main() { scanf("%d%d", &n, &m); int s = 0; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) { scanf("%d", &A[i][j]); s += A[i][j]; } int cc, rr; if (n > m) { cc = doCol(); rr = doRow(); } else { rr = doRow(); cc = doCol(); } // cc=doCol(); // rr=doRow(); if (s != cc * n + rr * m) return puts("-1"), 0; printf("%d\n", cc + rr); for (int i = 0; i < n; ++i) while (r[i]--) printf("row %d\n", i + 1); for (int j = 0; j < m; ++j) while (c[j]--) printf("col %d\n", j + 1); return 0; }
相关文章推荐
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2)-贪心&思维-C. Karen and Game
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- CF815A:Karen and Game(思维)
- 【贪心】 Codeforces Round #419 (Div. 1) A. Karen and Game
- C. Karen and Game【模拟+思维】
- codeforcces Karen and Game 思维
- Codeforces Round #419 (Div. 2) C. Karen and Game【贪心】
- Codeforces Round #419 (Div. 2)Karen and Game
- Codeforces Round #419 (Div. 2) C. Karen and Game 题解