HDU 1735 统计数字(贪心)
来源:互联网 发布:115浏览器for mac 编辑:程序博客网 时间:2024/06/05 05:59
题意:告诉你,n行,l 列,m段
找出最少被涂掉的字的个数
题解:记录总共0的个数,减掉m*2 ,在两个0开头的上一行尾数 0的个数记下来,排个序,减掉越长的越好,一共减掉m-1个就可以了。
#include <stdio.h>#include <string.h>#include <cstring>#include <algorithm>#include <iostream>using namespace std;int mp[10005][105];int b[10005];//尾部 int n,l,m;int hang[10005];//确定那几行 int a1,a0;int main(){ while(~scanf("%d%d%d",&n,&l,&m)) { memset(hang,0,sizeof(hang)); memset(b,0,sizeof(b)); a1=0;a0=0; for(int i=1;i<=n;i++) { for(int j=1;j<=l;j++) { scanf("%d",&mp[i][j]); if(mp[i][j]==0) a0++; else a1++; } if(mp[i][1]==0 &&mp[i][2]==0 && i!=1) hang[i]=1; } int cnt=1;//记录个数 for(int i=2;i<=n;i++) { if(hang[i]==1) { for(int j=l;j>=1;j--) { if(mp[i-1][j]==1) break; else { b[cnt]++; } } cnt++; } } cnt--; //最下面一层 for(int j=l;j>=1;j--) { if(mp[n][j]==1) break; else { a0--; } } a0-=m*2; sort(b+1,b+cnt+1); for(int i=cnt;i>=0 &&m>1 ;i--,m--) { a0-=b[i]; } printf("%d\n",a0); } return 0;}
0 0
- HDU 1735 统计数字(贪心)
- hdu 1735(贪心)
- 统计数字(1068)
- noip2007 统计数字 (排序)
- 统计数字(27)
- 统计数字(hash)
- 统计数字
- 统计数字
- 统计数字
- 统计数字
- 统计数字
- 统计数字
- 统计数字
- 统计数字
- 统计数字
- 统计数字
- 统计数字
- HDU Saving HDU (贪心)
- HDU 1022 火车站(模拟栈)
- SDUT2143图结构练习——最短路径
- HDU-5833-Zhu and 772002(高斯消元)
- 关于React Native 报Export declarations are not supported by current JavaScript version错误的解决问题
- 理解OAuth 2.0
- HDU 1735 统计数字(贪心)
- CodeForces 471D MUH and Cube Walls(KMP)
- 二叉树之中序遍历(递归和非递归两种遍历)
- Hdu 5833 Zhu and 772002(高斯消元解异或方程组)
- 21分钟 MySQL 入门教程
- springMVC各个包下的作用
- (转)Linux NTP配置详解 (Network Time Protocol)
- 绝句 自省
- 面向对象设计的八个原则