Educational Codeforces Round 30(补题) A B略 C(贪心)
来源:互联网 发布:淘宝网店客服怎么设置 编辑:程序博客网 时间:2024/06/06 00:19
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 either0 or 1. Rows and columns are1-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 isj, then he will find minimum i such that ai, j = 1). If there are no1'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 of1'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 ofi-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.
思路:查找每列一最集中的地方(当然要满足min(k,n-i+1)),然后记录开始的地方,最后把每列记录的地方上面的1换成0.
Code:
#include <bits/stdc++.h>using namespace std;const int AX = 1e2+6;int a[AX][AX];int main(){ios_base::sync_with_stdio(false); cin.tie(0);int n , m ,k ;cin >> n >> m >> k;for( int i = 0 ; i < n ; i++ ){for( int j = 0 ; j < m ; j++ ){cin >> a[i][j];}}int id[AX];int ans[AX];memset(ans,0,sizeof(ans));for( int j = 0 ; j < m ; j ++ ){for( int i = 0 ; i < n ; i ++ ){int sum = 0;if( a[i][j] == 1 ){int tmp = min(k,n-i+1);for( int kk = i ; kk < i + tmp ; kk++ ){if( kk >= n ) break;sum += a[kk][j];}if( ans[j] < sum ){ans[j] = sum;id[j] = i;}}}}int scr = 0 , op = 0; for( int i = 0 ; i < m; i++ ){scr += ans[i];for( int j = 0 ; j < id[i] ; j++ ){if( j >= n ) break;if( a[j][i] ) op ++;}}cout << scr << ' ' << op << endl;return 0;}
- Educational Codeforces Round 30(补题) A B略 C(贪心)
- Educational Codeforces Round 30(A+B)
- Codeforces-Educational Codeforces Round 32-(A,B,C,D)
- Educational Codeforces Round 5(B)贪心
- Educational Codeforces Round 8 (A B C)
- Educational Codeforces Round 31 A B C
- Educational Codeforces Round 32 A B C
- Educational Codeforces Round 27 A B 暴力+贪心 C 贪心+排序
- Educational Codeforces Round 6 (A)贪心
- Educational Codeforces Round 12(C)贪心
- Educational Codeforces Round 30 B C
- Codeforces Educational Round #18(Codeforces 792 A B C D)
- Educational Codeforces Round 24B Permutation Game 补题
- Educational Codeforces Round 6 C. Pearls in a Row(贪心)
- Educational Codeforces Round 5-B. Dinner with Emma(贪心)
- Educational Codeforces Round 5(A,B,C,D)
- Educational Codeforces Round 6 A.B.C.D.E
- Educational Codeforces Round 9 A B C D F
- REST四种请求(get,delete,put,post) 收集整理 之一
- 线程的同步
- 使用Hessian和Burlap发布远程接口服务步骤
- 线程模仿 ATM取钱
- 质因数分解
- Educational Codeforces Round 30(补题) A B略 C(贪心)
- 多线程之:生产者消费者
- BLE-NRF51822教程3-sdk程序框架剖析
- JAVA 代码覆盖率工具 JaCoCo-原理篇
- 下载安装mysql-5.7.x.msi
- 【微信小程序】开发准备
- 设置复选框选中(页面显示时作用)
- oracle 的一些命令
- 【1037】合并有序数组