【贪心】 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 ...
随机推荐
- JQuery-Ajax后台提交数据与获取数据 Java代码
function jqajax(){ var urlName = $("#urlName").val(); var urla = $("#url").val() ...
- 转载:WebView
前言 现在很多App里都内置了Web网页(Hyprid App),比如说很多电商平台,淘宝.京东.聚划算等等,如下图 那么这种该如何实现呢?其实这是Android里一个叫WebView的组件实现的.今 ...
- Android控件——ToggleButton多状态按钮(实现灯泡的开关)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAxoAAAFxCAIAAAB7jkm1AAAgAElEQVR4nOy9eXgUVb7/Dy7j3BnH8T
- rabbitmq之队列性能测试及优化方法(六)
前言 下面关注一下rabbitmq实际使用时的性能问题和怎么进行一些优化. 性能测试 针对每个需要生产/消费者与rabbitmq进行通讯的方法进行测试 测试环境 排除网络IO的干扰,采用生产者和消费者 ...
- 仿照linux dpm机制,实现自己的dpm【转】
转自:http://blog.csdn.net/lixiaojie1012/article/details/23788713 前边我们讨论分析了linux 内核的dpm实现,分析的目的在于学以致用:在 ...
- x64dbg
https://x64dbg.com/ https://github.com/x64dbg/x64dbg https://sourceforge.net/projects/x64dbg/files/s ...
- python近期遇到的一些面试问题(一)
整理一下最近被问到的一些高频率的面试问题.总结一下方便日后复习巩固用,同时希望可以帮助一些朋友们. 1.python的基本数据类型 主要核心类型分为两类不可变类型:数字(int float bool ...
- web.py输出中文字符串乱码问题的解决
web.py中文字符串网页显示乱码的解决 #!/usr/bin/env python # encoding: utf-8 import weburls = ( '/', 'index')class i ...
- python 使用headless chrome滚动截图
from selenium import webdriver from selenium.webdriver.chrome.options import Options import util chr ...
- VPS性能测试(1):CPU物理个数、内核、超线程、多核心
1.登录VPS界面,执行:cat /proc/cpuinfo,就会显示出VPS主机的CPU详细参数,如内核.频率.型号等等 2.主要参数physical_id表示物理CPU个数,cpu cores是内 ...