【贪心】 Codeforces Round #419 (Div. 1) A. Karen and Game
容易发现,删除的顺序不影响答案。
所以可以随便删。
如果行数大于列数,就先删列;否则先删行。
#include<cstdio>
#include<algorithm>
using namespace std;
int p1,ans1[510*110],ans2[510*110],p2;
int n,m,a[110][110];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
scanf("%d",&a[i][j]);
}
}
if(n<=m){
for(int i=1;i<=n;++i){
int minn=*min_element(a[i]+1,a[i]+m+1);
for(int j=1;j<=minn;++j){
ans1[++p1]=i;
}
for(int j=1;j<=m;++j){
a[i][j]-=minn;
}
}
for(int i=1;i<=m;++i){
int minn=2147483647;
for(int j=1;j<=n;++j){
minn=min(minn,a[j][i]);
}
for(int j=1;j<=minn;++j){
ans2[++p2]=i;
}
for(int j=1;j<=n;++j){
a[j][i]-=minn;
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if(a[i][j]>0){
puts("-1");
return 0;
}
}
}
printf("%d\n",p1+p2);
for(int i=1;i<=p1;++i){
printf("row %d\n",ans1[i]);
}
for(int i=1;i<=p2;++i){
printf("col %d\n",ans2[i]);
}
}
else{
for(int i=1;i<=m;++i){
int minn=2147483647;
for(int j=1;j<=n;++j){
minn=min(minn,a[j][i]);
}
for(int j=1;j<=minn;++j){
ans2[++p2]=i;
}
for(int j=1;j<=n;++j){
a[j][i]-=minn;
}
}
for(int i=1;i<=n;++i){
int minn=*min_element(a[i]+1,a[i]+m+1);
for(int j=1;j<=minn;++j){
ans1[++p1]=i;
}
for(int j=1;j<=m;++j){
a[i][j]-=minn;
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if(a[i][j]>0){
puts("-1");
return 0;
}
}
}
printf("%d\n",p1+p2);
for(int i=1;i<=p2;++i){
printf("col %d\n",ans2[i]);
}
for(int i=1;i<=p1;++i){
printf("row %d\n",ans1[i]);
}
} return 0;
}
【贪心】 Codeforces Round #419 (Div. 1) A. Karen and Game的更多相关文章
- Codeforces Round #419 (Div. 2) B. Karen and Coffee(经典前缀和)
http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs s ...
- Codeforces Round #419 (Div. 2) C. Karen and Game
C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- Codeforces Round #419 (Div. 2) B. Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形dp)
http://codeforces.com/contest/816/problem/E 题意: 去超市买东西,共有m块钱,每件商品有优惠卷可用,前提是xi商品的优惠券被用.问最多能买多少件商品? 思路 ...
- Codeforces Round #419 (Div. 2) A. Karen and Morning(模拟)
http://codeforces.com/contest/816/problem/A 题意: 给出一个时间,问最少过多少时间后是回文串. 思路: 模拟,先把小时的逆串计算出来: ① 如果逆串=分钟, ...
- Codeforces Round #419 (Div. 1) C. Karen and Supermarket 树形DP
C. Karen and Supermarket On the way home, Karen decided to stop by the supermarket to buy some g ...
- 【找规律】【递推】【二项式定理】Codeforces Round #419 (Div. 1) B. Karen and Test
打个表出来看看,其实很明显. 推荐打这俩组 11 1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000 1000000000 ...
- 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...
- 贪心 Codeforces Round #301 (Div. 2) B. School Marks
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...
随机推荐
- css优先级机制
所谓CSS优先级,即是指CSS样式在浏览器中被解析的先后顺序. 1.important >(内联样式)Inline style >(内部样式)Internal style sheet ...
- Java 中的静态内部类
静态内部类是 static 修饰的内部类,这种内部类的特点是: 1. 静态内部类不能直接访问外部类的非静态成员,但可以通过 new 外部类().成员 的方式访问 2. 如果外部类的静态成员与内部类的成 ...
- Linux目录结构与文件权限——(五)
1.目录结构
- uboot makefile构建分析
前言 几年前分析过uboot的构建及启动过程,做了笔记,但最终没有转为文章.这次又有机会开发嵌入式产品了(之前一年多都是在搞x86 linux),看了下uboot的构建过程,觉得有必要写下整个分析过程 ...
- 判断cookie创建的时间是否已经24小时
def read_cookie(self): cookiesfilepath="cookies%s" % self.uid if os.path.exists(cookiesfil ...
- HDU 6115 Factory LCA,暴力
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6115 题意:中文题面 分析:直接维护LCA,然后暴力枚举集合维护答案即可. #include < ...
- network-scoket
server: using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...
- JVM 核心机制(类加载器、自定义文件系统类加载器、网络自定义类加载器
- 使用js创建select option
var v_select = document.getElementById("selectA"); var v_option = document.createElement( ...
- HDU-5281
Senior's Gun Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...