codeforces——873C —— Strange Game On Matrix
来源:互联网 发布:王传君经历了什么知乎 编辑:程序博客网 时间:2024/06/05 01:53
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.
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.
Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score.
4 3 20 1 01 0 10 1 01 1 1
4 1
3 2 11 00 10 0
2 0
In the first example Ivan will replace the element a1, 2.
有一个n*m的矩阵,由0,1组成....有操作可以把1修改为0
计分方式是统计每列第一个1(包括第一个1),长度为k的数组,拥有1的个数....每列的结果求和
问在最少的操作次数下,能得到的最大结果..
#include <cstring>#include <queue>#include <cstdio>#include <algorithm>#include <string>#include <map>#include <set>#include <vector>#include <iostream>#include <cmath>using namespace std;int main() { int n,m,len,in[108][108]; while(~scanf("%d%d%d",&n,&m,&len)) { for(int i=0; i<n; i++) for(int j=0; j<m; j++) scanf("%d",&in[i][j]); int ans1=0,ans2=0; for(int j=0; j<m; j++) { int large=0,place; for(int i=0; i<=n-len; i++) { int sum=0; for(int k=i; k<i+len; k++) sum+=in[k][j]; if(sum>large) { large=sum; place=i; } } if(large) { ans1+=large; for(int i=0; i<place; i++) ans2+=in[i][j]; } } printf("%d %d\n",ans1,ans2); } return 0;}
- codeforces——873C —— Strange Game On Matrix
- Codeforces 873C Strange Game On Matrix【贪心】水题
- codeforces 873 C. Strange Game On Matrix【贪心】
- Educational Codeforces Round 30 C. Strange Game On Matrix
- Educational Codeforces Round 30C-模拟&贪心-Strange Game On Matrix
- Codeforces-Strange Game On Matrix(暴力直接写)
- (Coderforces 873C)C. Strange Game On Matrix 贪心+模拟
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade —— 贪心 + 字符串处理
- 博弈论 —— The Game of Parity ( CodeForces 549C )
- CodeForces 280C Game on Tree 概率
- codeforces 280C Game on Tree
- hdu2899——Strange fuction
- 搜索—problem_1002-Strange fuction
- Round #172 (Div. 1) C. Game on Tree——概率
- CodeForces -Game on Paper
- [codeforces]A. Efim and Strange Grade——贪心+字符串处理
- Codeforces 832 C Strange Radiation
- CodeForces 832 C. Strange Radiation
- Master原理剖析与源码分析:主备切换机制原理剖析与源码分析
- iOS UILocalNotification scheduleLocalNotification 收不到通知
- 怎么解决tomcat占用8080端口问题
- PLSQL记录被另一个用户锁住
- struts2的result标签
- codeforces——873C —— Strange Game On Matrix
- 我眼中的责任链模式
- A表中的数据根据条件,不能再B表中存在,显示A表符合条件的数据
- Java集合框架基础-----List
- Struts2验证(框架验证)
- 061 不定积分之工具一总结
- CS231_A1:Softmax
- 第四章 ActiveMQ连接(Connector)配置 笔记
- Java 内存区域和GC机制