hdu 1735(贪心)
来源:互联网 发布:php ture还是true 编辑:程序博客网 时间:2024/05/16 04:36
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1735
思路:贪心,只要开头有两个0,则需要判断其上一行最后有多少个连续的0,按上一行最后处0的数量由大到小排序(特殊处理一下最后一行末尾0就可以了);
View Code
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 #define MAXN 10000+10 7 #define MAXL 100+10 8 int map[MAXN][MAXL]; 9 int n,l,m,k,ans;10 int _count[MAXN];//(如果当前行前2个为0)记录上一行行尾0的个数11 12 int cmp(const int &p,const int &q){13 return p>q;14 }15 16 17 int main(){18 while(~scanf("%d%d%d",&n,&l,&m)){19 k=0,ans=0;20 for(int i=1;i<=n;i++){21 for(int j=1;j<=l;j++){22 scanf("%d",&map[i][j]);23 if(!map[i][j])ans++;24 }25 }26 //除去最后一行行尾0的个数27 for(int i=l;i>=1;i--){28 if(!map[n][i])ans--;29 else break;30 }31 ans-=2*m;//除去m行开始的2个032 for(int i=2;i<=n;i++){33 int count=0;34 if(!map[i][1]&&!map[i][2]){35 //记录上一行行尾0的个数36 for(int j=l;j>=1;j--){37 if(!map[i-1][j])count++;38 else break;39 }40 _count[k++]=count;41 }42 }43 sort(_count,_count+k,cmp);44 //只需m-1行就行;45 for(int i=0;i<m-1;i++){46 ans-=_count[i];47 }48 printf("%d\n",ans);49 }50 return 0;51 }
0 0
- hdu 1735(贪心)
- HDU 1735 统计数字(贪心)
- HDU Saving HDU (贪心)
- hdu 2570 (贪心)
- hdu 4647(贪心?!)
- hdu 3069(贪心)
- hdu 3979(贪心)
- hdu 4296(贪心)
- hdu 2831(贪心)
- hdu 3183(贪心)
- hdu 2037(贪心)
- HDU 1051(贪心)
- hdu 5090(贪心)
- 贪心(HDU 1055)
- HDU 迷瘴 (贪心)
- hdoj2111Saving HDU(贪心)
- hdu 5246(贪心)
- HDU 4912 (贪心)
- hdu 1497(图书管理系统模拟)
- “CreateRiaClientFilesTask”任务意外失败。 未能加载文件程序集“System.ComponentModel.DataAnnotations 处理办法
- Qt学习——堆栈窗体QStackedWidget类
- hdu 1707(memset妙用)
- hdu 1572(dfs+最短路)
- hdu 1735(贪心)
- cf3b(贪心)
- hdu 3979(贪心)
- cf3d
- cf4b
- poj 1037(经典dp)
- 网络流之SAP算法学习
- hdu 3549(最大流)
- postgreSQL基础