【贪心】 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 ...
随机推荐
- 关于auto-keras训练cnn模型
# 我在训练自己的人脸分类模型的时候发现图片的维度不能太高,经过很多次测试过后觉得一般人脸图片分为28*28大小训练的效果比较好.建议在使用其训练自己的物体识别模型的时候,尽量把图片压缩到28*28# ...
- 往Layout中动态添加View
需要注意几个方法:基本上所有的方法参数单位是px 1.设置View的宽高: LinearLayout.LayoutParams params = new LinearLayout().LayoutPa ...
- setsockopt 详解
1. closesocket(一般不会立即关闭而经历TIME_WAIT的过程)后想继续重用该socket: BOOL bReuseaddr=TRUE; setsockopt(s,SOL_SOCKET ...
- 网络知识===wireshark抓包,三次握手分析
TCP需要三次握手建立连接: 网上的三次握手讲解的太复杂抽象,尝试着使用wireshark抓包分析,得到如下数据: 整个过程分析如下: step1 client给server发送:[SYN] Seq ...
- ogre3d环境配置 SDK安装配置及简单事例教程
ogre3d环境配置 SDK安装配置及简单事例教程 http://www.cr173.com/html/22594_1.html ogre3d环境配置 SDK安装配置及简单事例教程 http://ww ...
- telnet如何保存输出内容到本地
telnet如何保存输出内容到本地 http://bbs.csdn.net/topics/391023327 一种将程序的标准输出重定向到telnet终端的方法 http://blog.chinaun ...
- HDU 4768: Flyer
题意: 有N个社团,每个社团三个属性A,B,C,表示会向编号A+k*C的同学发传单(k=0,1,2... && A+k*C <= B).题目保证最多有一个人收到的传单数是奇数. ...
- css设置div等标签背景半透明
三种方式: 1. background-color: transparent; 直接设置背景为透明 2.这种是子元素也会跟着变成半透明 /* 背景半透明,1为不透明 */ opacity: 0.5; ...
- P1466 集合 Subset Sums(01背包求填充方案数)
题目链接:https://www.luogu.org/problem/show?pid=1466 题目大意:对于从1到N (1 <= N <= 39) 的连续整数集合,能划分成两个子集合, ...
- 深入理解计算机(CSAPP)资源汇总
用于资源记录. 视频: 卡内基梅隆大学 Introduction to Computer Systems CMU 15-213 Fall 作业(labs): Lab Assignments