zoukankan      html  css  js  c++  java
  • codeforces 873C

    题目大意:给你一个n*m的只有0和1的矩阵,找到每列第一个1的位置a[i][j],a[i][j]及其a[min(k,n-i+1][j]中1的数量,每列位置值是1的可以变为0;

    解题思路:因为数据较小,模拟整个过程,找出每列中1的数值最多的那一段;

    代码(比较菜,代码写得比较乱):

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int main()
    {
        int a[105][105];
        int n,m,k;
        int count,countx,ans;
        int i,j,l;
        int maxn;
        int place;
        while(cin>>n>>m>>k)
        {
            count=countx=ans=0;maxn=0;
            for(i=1;i<=n;i++)
                for(j=1;j<=m;j++)
                    cin>>a[i][j];
            for(j=1;j<=m;j++)
            {
                maxn=0;
                for(i=1;i<=n;i++)
                {
                    countx=0;
                    int t=min(k,n-i+1);
                    if(a[i][j]==1)
                    {
                        for(l=i;l<=n&&l<t+i;l++)
                        {
                            if(a[l][j]==1)
                                countx++;
                        }
                    }
                    if(countx>maxn)
                    {
                        maxn=countx;
                        place=i;
                    }

                }
                //cout<<place<<endl;
                for(int x=1;x<place;x++)
                    if(a[x][j]==1)
                    count++;
                ans+=maxn;
               // cout<<ans<<endl;
            }
            cout<<ans<<" "<<count<<endl;
        }
        return 0;
    }

  • 相关阅读:
    (转)使用Regex.Replace只替换字符串一次
    转:div超出范围显示省略号
    ibatis This SQL map does not contain a MappedStatement
    ibatis 多表关联
    ibatis 传入xml Hashtable的应用以及动态字段出错的解决方法
    前台学习过程
    转:C#动态循环生成button怎么分别写他们的事
    在oracle DB 中通过JOB 调用存储过程
    sybase与oracle存储过程的写法对比
    游标Oracle游标使用大全
  • 原文地址:https://www.cnblogs.com/huangdao/p/7718608.html
Copyright © 2011-2022 走看看