[Simulation] pinball game

Original title Portal

Thinking


Pure simulation title, the sum of the number of enemy settled place for each peer computing same column, can take the maximum value
if there is no place to stay is output: '' Bad Game! '' .

The time complexity is O (n 2 * (n + n)) i.e. O (n . 3 ), since less than 10 n . 3 , it will not exceed the time (although jeopardy)

This question is really saying water

Code


#include <iostream>
using namespace std;

int ans=-1,n,a[1001][1001];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        cin>>a[i][j];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(a[i][j]==0) 
            {
                int x=0;
                for(int k=1;k<=n;k++)
                    x+=a[i][k]+a[k][j];
                ans=max(ans,x);
            }
    if(ans==-1)
        cout<<"Bad Game!";//如果ans还是负数就代表没有容身之地
    else 
        cout<<ans;//否则输出最大值
}

Reproduced in: https: //www.cnblogs.com/gongdakai/p/11066260.html

Guess you like

Origin blog.csdn.net/weixin_34290390/article/details/93791410