Codeforces Round #419 (Div. 2)-贪心&思维-C. Karen and Game
2017-09-06 11:12
561 查看
http://codeforces.com/contest/816/problem/C
这个题,看下面的解释就看懂了。
给定一个矩阵,每块都有值,可以一行一行的删除,也可以一列一列的删除,问你最小的删除方法
行多按列删除,列多按行删。
一次删完,找最小的。
这个题,看下面的解释就看懂了。
给定一个矩阵,每块都有值,可以一行一行的删除,也可以一列一列的删除,问你最小的删除方法
行多按列删除,列多按行删。
一次删完,找最小的。
#include <bits/stdc++.h> /* 模拟,每次找最小的。 如果行大,就从列开始找, 如果列大,就从行开始删(保证删除的最少) */ using namespace std; int a[105][105]; int m,n; int ans; queue<int>q; queue<int>p; void col_sol(){ for(int i=1;i<=n;i++){ int min1=1e7; for(int j=1;j<=m;j++) min1=min(a[j][i],min1); ans+=min1; int kk=min1; while(kk){ p.push(i); kk--; } for(int j=1;j<=m;j++) a[j][i]-=min1; } } void row_sol(){ for(int i=1;i<=m;i++){ int min1=1e7; for(int j=1;j<=n;j++) min1=min(a[i][j],min1); ans+=min1; int kk=min1; while(kk){ q.push(i); kk--; } for(int j=1;j<=n;j++) a[i][j]-=min1; } } bool solve(){ for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++) if(a[i][j]!=0) return false; } return true; } int main(){ scanf("%d%d",&m,&n); ans=0; for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ scanf("%d",&a[i][j]); } } if(m>n){ col_sol(); row_sol(); } else{ row_sol(); col_sol(); } if(!solve()) puts("-1"); else{ printf("%d\n",ans); while(!q.empty()){ printf("row %d\n",q.front()); q.pop(); } while(!p.empty()){ printf("col %d\n",p.front()); p.pop(); } } 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. 1) A. 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 #444 (Div. 2)-贪心&尺取-Ratings and Reality Shows
- codeforcces Karen and Game 思维
- Codeforces Round #311 (Div. 2) C. Arthur and Table (枚举+贪心+思维)
- 【前缀和 && 思维转换】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)Molly's Chemicals
- Codeforces Round #228 (Div. 2) E Fox and Card Game(贪心博弈)