【CF edu 30 C. Strange Game On Matrix】
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output
Ivan is playing a strange game.
He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows:
- Initially Ivan's score is 0;
- In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped;
- Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score.
Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score.
Input
The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100).
Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1.
Output
Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score.
Examples
input
4 3 2
0 1 0
1 0 1
0 1 0
1 1 1
output
4 1
input
3 2 1
1 0
0 1
0 0
output
2 0
Note
In the first example Ivan will replace the element a1, 2.
【翻译】给出01矩阵,要求删除1的点(可以不删),使得得分最大。得分计算方式:得分为每列的得分和,每列的得分计算方式为:从上往下第一个为1的位置向下的k长度区间内1的个数即分数(包括这个位置本身)。输出最高分数以及达成这个分数的最小删除数。
题解:
①贪心。
②每一列用单调性维护取最值就是了。
#include<stdio.h>
#include<algorithm>
#define go(i,a,b) for(int i=a;i<=b;i++)
#define ro(i,a,b) for(int i=a;i>=b;i--)
using namespace std;const int N=;
int n,m,k,G[N][N],sum[N],score,ans;
int main()
{
scanf("%d%d%d",&n,&m,&k);
go(i,,n)go(j,,m)scanf("%d",&G[i][j]);
go(j,,m)
{
int p,val=;
ro(t,n,)sum[t]=sum[t+]+G[t][j];
ro(t,n,)if(G[t][j]&&sum[t]-sum[min(t+k,n+)]>=val)
val=sum[t]-sum[min(t+k,n+)],p=t;ans+=sum[]-sum[p];score+=val;
}
printf("%d %d\n",score,ans);return ;
}//Paul_Guderian
.
【CF edu 30 C. Strange Game On Matrix】的更多相关文章
- 【CF edu 30 D. Merge Sort】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【Cf edu 30 B. Balanced Substring】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【CF edu 30 A. Chores】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【CF MEMSQL 3.0 D. Third Month Insanity】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【CF MEMSQL 3.0 B. Lazy Security Guard】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- B. Lost Number【CF交互题 暴力】
B. Lost Number[CF交互题 暴力] This is an interactive problem. Remember to flush your output while communi ...
- 【2018.07.30】(广度优先搜索算法/队列)学习BFS算法小记
一些BFS参考的博客: https://blog.csdn.net/ldx19980108/article/details/78641127 https://blog.csdn.net/u011437 ...
- 【Python五篇慢慢弹(5)】类的继承案例解析,python相关知识延伸
类的继承案例解析,python相关知识延伸 作者:白宁超 2016年10月10日22:36:57 摘要:继<快速上手学python>一文之后,笔者又将python官方文档认真学习下.官方给 ...
- 让时间处理简单化 【第三方扩展类库org.apache.commons.lang.time】
JAVA的时间日期处理一直是一个比较复杂的问题,大多数程序员都不能很轻松的来处理这些问题.首先Java中关于时间的类,从 JDK 1.1 开始,Date的作用很有限,相应的功能已由Calendar与D ...
随机推荐
- scala成长之路(1)基本语法和数据类型
scala作为JVM上的Lisp,是一种geek类型的编程语言,也一直是我等java程序员眼中的梦寐以求的一门技能,遂下定决心花一段时间好好学习scala.第一天学习,主要介绍与java在编程上的主要 ...
- HBase学习(三):数据模型
和传统的关系型数据库类似,HBase以表(Table)的方式组织数据.HBase的表由行(Row)和列(Column)共同构成,与关系型数据库不同的是HBase有一个列族(ColumnFamily)的 ...
- zabbix使用iostat命令参数监控磁盘性能
iostat命令 先说一个坑把,在开始监控的时候使用命令iostat -dtkx,得到的结果看上去没问题,但是在web监控窗口数据就说不变动,为啥呢,因为iostat这个命令得到的第一个数据始终是磁盘 ...
- BGP路由控制属性
控制BGP路由概述: BGP与IGP不同,其着跟点主要在于不同的AS之间控制路由的传播和选择最佳路由 通过修改BGP基本属性可以实现基本的BGP路由控制和最佳路由的选择 引入其他路由协议发现的路由时. ...
- 插头DP(基于连通性状态压缩的动态规划问题)(让你从入门到绝望)
今天,我,Monkey king 又为大家带来大(ju)佬(ruo)的算法啦!--插头DP 例题(菜OJ上的网址:http://caioj.cn/problem.php?id=1489): 那么,这道 ...
- C语言实现简易扫雷
首先,写代码之前要将整体思路写出来: 扫雷游戏:1.需要两个二维数组,一个用来展示,一个用来放雷; 2.整体骨架在代码中都有注释说明; 3.游戏难度比较简单,适合初学者观看,如果有大佬看明白,可以指点 ...
- uva 509 RAID!(磁盘数据)
来自 https://blog.csdn.net/su_cicada/article/details/80085318 习题4-7 RAID技术(RAID!, ACM/ICPC World Final ...
- spark优化系列一:参数介绍
1 spark on yarn常用属性介绍 属性名 默认值 属性说明 spark.yarn.am.memory 512m 在客户端模式(client mode)下,yarn应用master使用的内存数 ...
- fsync体会
看这个链接:http://www.postgresql.org/docs/9.1/static/runtime-config-wal.html 是这样说的: fsync (boolean) If th ...
- C#里的指针
最近在复习C#基础这里,发现指针运算方式跟引用类型运算方式很相像. 指针里面存放的是表示内存地址的一段整数,所以任何整数类型指针之间都可以相互转换,因此带来了不安全性. ; long* b = &am ...