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;
    }

  • 相关阅读:
    Nginx 相关配置文件修改
    LNMP平台构建实验 +bbs社区搭建
    CSGO项目
    创世战车项目
    IGXE搬砖项目
    11_samba服务器的搭建
    26_django内置static标签
    06_git添加远程仓库并向远程仓库中推送代码
    23_添加apps到项目的搜索路径
    23_django日志器的配置和其使用方法
  • 原文地址:https://www.cnblogs.com/huangdao/p/7718608.html
Copyright © 2011-2022 走看看