HDU4608+模拟

简单的模拟题。

暴力枚举

 

/*

模拟

*/

#include<algorithm>

#include<iostream>

#include<string.h>

#include<stdlib.h>

#include<stdio.h>

#include<math.h>

#include<queue>

#include<stack>

#include<map>

#include<set>

using namespace std;

typedef long long int64;

//typedef __int64 int64;

typedef pair<int64,int64> PII;

#define MP(a,b) make_pair((a),(b)) 

const int inf = 0x3f3f3f3f;

const double pi=acos(-1.0);

const int dx[]={1,-1,0,0};

const int dy[]={0,0,1,-1};

const double eps = 1e-8;

const int maxm = 1005;

const int maxn = 25;



int num[ maxn ][ maxn ];



int main(){

    //freopen( "in.txt","r",stdin );

    int n;

    while( scanf("%d",&n),n ){

        memset( num,0,sizeof( num ) );

        for( int i=1;i<=n;i++ )

            for( int j=1;j<=n;j++ )

                scanf("%d",&num[i][j]);

        int cnt = 0;

        int sum = 0;

        int CNT = n;

        for( int loop=1;loop<=(n/2);loop++ ){

            //int x = loop;

            //int y = loop;

            //printf("loop = %d\n",loop);

            int lux = loop,luy = loop;

            int ldx = loop+CNT-1,ldy = loop;

            int rux = loop,ruy = loop+CNT-1;

            int rdx = loop+CNT-1,rdy = loop+CNT-1;

            int ti = CNT - 1 ;

            int cc = 0;

            int temp_sum = 0;

            int temp_cnt = 0;

            //bool f = false;

            while( cc<ti ){

                int temp = 0;

                //if( f==false ){

                //    f = true;

                //    ti -- ;

                //}

                //printf("(%d,%d) (%d,%d) (%d,%d) (%d,%d)\n",lux,luy,rux,ruy,ldx,ldy,rdx,rdy);

                temp = num[lux][luy] + num[rux][ruy] + num[ldx][ldy] + num[rdx][rdy];            

                if( temp>temp_sum ){

                    temp_sum = temp;

                    temp_cnt = min( cc,ti-cc );

                }

                else if( temp==temp_sum ){

                    temp_cnt = min( temp_cnt,min( cc,ti-cc ) );

                }

                cc ++ ;

                luy ++ ;

                rux ++ ;

                rdy -- ;

                ldx -- ;

            }

            CNT -= 2;

            sum += temp_sum;

            cnt += temp_cnt;

        }

        printf("%d %d\n",sum+num[(n/2)+1][(n/2)+1],cnt);

    }

    return 0;

}


 

 

你可能感兴趣的:(HDU)