HDU4608+模拟

简单的模拟题。

暴力枚举

 1 /*
 2 模拟
 3 */
 4 #include<algorithm>
 5 #include<iostream>
 6 #include<string.h>
 7 #include<stdlib.h>
 8 #include<stdio.h>
 9 #include<math.h>
10 #include<queue>
11 #include<stack>
12 #include<map>
13 #include<set>
14 using namespace std;
15 typedef long long int64;
16 //typedef __int64 int64;
17 typedef pair<int64,int64> PII;
18 #define MP(a,b) make_pair((a),(b)) 
19 const int inf = 0x3f3f3f3f;
20 const double pi=acos(-1.0);
21 const int dx[]={1,-1,0,0};
22 const int dy[]={0,0,1,-1};
23 const double eps = 1e-8;
24 const int maxm = 1005;
25 const int maxn = 25;
26 
27 int num[ maxn ][ maxn ];
28 
29 int main(){
30     //freopen( "in.txt","r",stdin );
31     int n;
32     while( scanf("%d",&n),n ){
33         memset( num,0,sizeof( num ) );
34         for( int i=1;i<=n;i++ )
35             for( int j=1;j<=n;j++ )
36                 scanf("%d",&num[i][j]);
37         int cnt = 0;
38         int sum = 0;
39         int CNT = n;
40         for( int loop=1;loop<=(n/2);loop++ ){
41             //int x = loop;
42             //int y = loop;
43             //printf("loop = %d
",loop);
44             int lux = loop,luy = loop;
45             int ldx = loop+CNT-1,ldy = loop;
46             int rux = loop,ruy = loop+CNT-1;
47             int rdx = loop+CNT-1,rdy = loop+CNT-1;
48             int ti = CNT - 1 ;
49             int cc = 0;
50             int temp_sum = 0;
51             int temp_cnt = 0;
52             //bool f = false;
53             while( cc<ti ){
54                 int temp = 0;
55                 //if( f==false ){
56                 //    f = true;
57                 //    ti -- ;
58                 //}
59                 //printf("(%d,%d) (%d,%d) (%d,%d) (%d,%d)
",lux,luy,rux,ruy,ldx,ldy,rdx,rdy);
60                 temp = num[lux][luy] + num[rux][ruy] + num[ldx][ldy] + num[rdx][rdy];            
61                 if( temp>temp_sum ){
62                     temp_sum = temp;
63                     temp_cnt = min( cc,ti-cc );
64                 }
65                 else if( temp==temp_sum ){
66                     temp_cnt = min( temp_cnt,min( cc,ti-cc ) );
67                 }
68                 cc ++ ;
69                 luy ++ ;
70                 rux ++ ;
71                 rdy -- ;
72                 ldx -- ;
73             }
74             CNT -= 2;
75             sum += temp_sum;
76             cnt += temp_cnt;
77         }
78         printf("%d %d
",sum+num[(n/2)+1][(n/2)+1],cnt);
79     }
80     return 0;
81 }
View Code
keep moving...
原文地址:https://www.cnblogs.com/xxx0624/p/3321586.html