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

  • 相关阅读:
    2-4安卓自学
    2-3安卓自学
    2-2安卓自学
    2-1安卓自学
    20210121 Sqlit数据库
    20210119 Sqlit数据库
    20210118 android学习
    20210117 android学习
    20210115 android学习
    20210114 android学习
  • 原文地址:https://www.cnblogs.com/huangdao/p/7718608.html
Copyright © 2020-2023  润新知