比赛 树立信心的模拟赛 评测结果 WAWAAAWAWA
题目名称 凯伦和游戏 最终得分 60
用户昵称 I love study 运行时间 0.235 s
代码语言 C++ 内存使用 0.39 MiB
提交时间 2017-09-01 21:44:02
显示代码纯文本
    #include<iostream>
    #include<cstdio>
    using namespace std;
    int n,m;
    int g[101][101],a[101][101];
    int row[101]={0},col[101]={0};
    int main()
    {
    freopen("games.in","r",stdin);
    freopen("games.out","w",stdout);
    int i,j,z,x,y,q;
    x=0;
    q=0;
    cin>>n>>m;
    for (i=1;i<=n;i++)
    for (j=1;j<=m;j++)
    {cin>>g[i][j];
    if (g[i][j]>q)
    q=g[i][j];
    a[i][j]=0;
    }
    for (y=1;y<=q;y++)
    for (i=1;i<=n;i++)
    {
    z=0;
    for (j=1;j<=m;j++)
    if(a[i][j]==g[i][j])
    {z=1;
    break;
    }
    if (z==0)
    {row[i]=row[i]+1;
    x=x+1;
    for (j=1;j<=m;j++)
    a[i][j]=a[i][j]+1;}	
    }
    for (y=1;y<=q;y++)
    for (i=1;i<=m;i++)
    {
    z=0;
    for (j=1;j<=n;j++)
    if(a[j][i]==g[j][i])
    {
    z=1;
    break;
    }
    if (z==0)
    {col[i]=col[i]+1;
    x=x+1;
    for (j=1;j<=n;j++)
    a[j][i]=a[j][i]+1;}
    }
    if (x==0)
    cout<<"-1";
    else
    {
    cout<<x<<endl;
    for (i=1;i<=n;i++)
    if (row[i]>=1)
    for (j=1;j<=row[i];j++)
    cout<<"row "<<i<<endl;
     
     
    for (i=1;i<=m;i++)
    if (col[i]>=1)
    for (j=1;j<=col[i];j++)
    cout<<"col "<<i<<endl;
    }
    fclose(stdin);fclose(stdout);
    }