HDU 4708 Rotation Lock Puzzle

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708

测试数据:

5
1 9 9 1 1
1 9 9 9 9
9 9 9 9 9
9 9 9 9 1
1 1 9 9 1

81 1

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 using namespace std;
 5 long long  a[15][15];
 6 long long step,ans;
 7 void solve1(int t,int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
 8 {
 9     int i;
10     long long w;
11     t = t-1;//范围想错了,wa到比赛结束还不对,唉
12     for(i=0;i<t;i++)
13     {
14         w = a[x1][y1] + a[x2][y2]+a[x3][y3]+a[x4][y4];
15         y1++;
16         x2++;
17         y3--;
18         x4--;
19             if(w>ans)
20             {
21              ans = w;
22              step = i;
23             }
24      }
25 }
26 void solve2(int t,int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
27 {
28     int i;
29     t =t-1;
30     long long w;
31     for(i=0;i<t;i++)
32     {
33         w = a[x1][y1] + a[x2][y2]+a[x3][y3]+a[x4][y4];
34         x1++;
35         y2--;
36         x3--;
37         y4++;
38             if(w>=ans)
39             {
40               ans = w;
41               if(step>i)
42                  step=i;
43             }
44      }
45 }
46 int main()
47 {
48     int T;
49     long long ss,aa;
50     while(scanf("%d",&T) && T)
51     {
52         ss = 0;aa = 0;
53         for(int i=1;i<=T;i++)
54             for(int j=1;j<=T;j++)
55                scanf("%lld",&a[i][j]);
56         int mid1 = (T+1)/2;
57         for(int i=3,k=1;i<=T;i=i+2,k++)
58         {
59             step = 0;ans = 0;
60             solve1(i,mid1 - k,mid1-k,mid1-k,mid1+k,mid1+k,mid1+k,mid1+k,mid1-k);//顺时针
61             solve2(i,mid1 - k,mid1-k,mid1-k,mid1+k,mid1+k,mid1+k,mid1+k,mid1-k);//逆时针
62             ss= ss +step;
63             aa = ans+aa;
64         }
65    printf("%lld %lld\n",aa+a[mid1][mid1],ss);
66     }
67     return 0;
68 }
时间: 2024-07-31 22:16:17

HDU 4708 Rotation Lock Puzzle的相关文章

HDU 4708 Rotation Lock Puzzle (贪心+模拟)

Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1668    Accepted Submission(s): 530 Problem Description Alice was felling into a cave. She found a strange door with a number

HDU 4708 Rotation Lock Puzzle(数学啊)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 Problem Description Alice was felling into a cave. She found a strange door with a number square matrix. These numbers can be rotated around the center clockwise or counterclockwise. A fairy came an

hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Alice was felling into a cave. She found a strange door with a number square m

HDU4708 Rotation Lock Puzzle 不错的模拟题

题意:给你一个n*n的矩阵,n为奇数,以最中心的一个数为基准,可以把这个矩阵 看成一圈一圈的,每一圈都可以逆时针或者顺时针旋转,每一次旋转每个元素只能移动一个单元格,求经过每一圈的旋转矩阵两个对角线和最大的值,并求出最少旋转次数 一圈一圈的处理,注意最中心的那个数不用管,就它一个,那么这个矩阵只有n/2圈需要操作,对于每一圈的元素都放在一个一维数组里面,然后枚举这个数组里的每一个元素为开头,统计接下来的三个数,求和比较大小即可,因为有逆时针的,所以顺时针时从开头开始枚举,逆时针则从尾部开始枚举,

HDU 4708

对每个环都进行遍历,找出最大值 如果值相等的话就可以还要判断下走的步数 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1369    Accepted Submission(s): 431 Problem Description Alice was felling into a cave. S

HDU 1098 Ignatius&#39;s puzzle 费马小定理+扩展欧几里德算法

题目大意: 给定k,找到一个满足的a使任意的x都满足 f(x)=5*x^13+13*x^5+k*a*x 被65整除 推证: f(x) = (5*x^12 + 13 * x^4 + ak) * x 因为x可以任意取 那么不能总是满足 65|x 那么必须是 65 | (5*x^12 + 13 * x^4 + ak) 那么就是说 x^12 / 13 + x^4 / 5 + ak / 65 正好是一个整数 假设能找到满足的a , 那么将 ak / 65 分进x^12 / 13 + x^4 / 5中得到

HDU 1098 Ignatius&#39;s puzzle 也不大懂

http://acm.hdu.edu.cn/showproblem.php?pid=1098 看了一下它们的思路,没完全明白,但是能写出来,大概可能也许就是这样做的吧. 1 #include <iostream> 2 using namespace std; 3 typedef long long ll; 4 5 int main() { 6 ll k; 7 while (cin>>k) 8 { 9 int flag = 0,a; 10 for ( a = 1; a <= 6

[2016-02-05][HDU][1097][A hard puzzle]

[2016-02-05][HDU][1097][A hard puzzle] HDU - 1097 A hard puzzle Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know

HDU - 1098 - Ignatius&#39;s puzzle (数论 - 费马小定理)

Ignatius's puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7012    Accepted Submission(s): 4847 Problem Description Ignatius is poor at math,he falls across a puzzle problem,so he has no