标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1668 Accepted Submission(s): 530
#pragma comprint(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<string> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<vector> #include<map> #include<stdlib.h> #include<time.h> #include<algorithm> #define LL __int64 #define FIN freopen("in.txt","r",stdin) using namespace std; const int INF=0x3f3f3f3f; int main() { int n,ans,anst,t,t1,sum,s; int val[15][15]; while(scanf("%d",&n)&&n) { anst=ans=0; memset(val,0,sizeof(val)); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%d",&val[i][j]); for(int i=1;i<=n/2;i++) { sum=-INF; for(int j=0;j<n-(i-1)*2-1;j++) { s=val[i][i+j]+val[i+j][n-i+1]+val[n-i+1][n-i+1-j]+val[n-i+1-j][i]; if(sum<s) { sum=s; t1=j<(n-i-j)?j:(n-i-j); } else if(sum==s) { t=j<(n-i-j)?j:(n-i-j); if(t<t1) t1=t; } } ans+=sum; anst+=t1; } ans+=val[n/2+1][n/2+1]; printf("%d %d\n",ans,anst); } return 0; }
HDU 4708 Rotation Lock Puzzle (贪心+模拟)
标签:
原文地址:http://www.cnblogs.com/clliff/p/4743630.html