题解:
题意:类似炸弹人游戏,但是十字的炸弹弹道都是等长的(就是4个方向的长度一样)(可以炸十、×),然后结果是所能炸到的每个格子的乘积的最大值。
题解: 设 X =2a + 3b . Y = 2c + 3d.
那么 X 和 Y 的大小关系与 log(2)*a + log(3)*b 和 log(2)*c + log(3)*d 的大小有关,所以我们就开一个数组存下每一个格子的log值,然后维护一下一个格子8个方向可延伸的最大长度,并且计算出2个前缀和,最后计算一下即可.........话说我的代码好TM挫,要写200+行,还是某位大佬的代码短,只要86行........
果断mo一发代码...
Vanya and Balloons1 #include <cmath> 2 #include <cstdio> 3 #include <algorithm> 4 5 using namespace std; 6 7 const int MAXN = 1E3 + 10; 8 const int MOD = 1E9 + 7; 9 10 int n; 11 char s[MAXN][MAXN]; 12 double p[4][MAXN][MAXN]; 13 int a[8][MAXN][MAXN]; 14 15 int main(){ 16 scanf("%d", &n); 17 for (int i = 1; i <= n; ++i) 18 scanf("%s", s[i] + 1); 19 20 double val[4] = {0., 0., log(2.), log(3.)}; 21 for (int i = 1; i <= n; ++i) 22 for (int j = 1; j <= n; ++j){ 23 s[i][j] -= '0'; 24 p[0][i][j] = p[0][i ][j - 1] + val[s[i][j]]; 25 p[1][i][j] = p[1][i - 1][j - 1] + val[s[i][j]]; 26 p[2][i][j] = p[2][i - 1][j ] + val[s[i][j]]; 27 p[3][i][j] = p[3][i - 1][j + 1] + val[s[i][j]]; 28 } 29 for (int i = 1; i <= n; ++i) 30 for (int j = 1; j <= n; ++j) 31 if (s[i][j]){ 32 a[0][i][j] = a[0][i ][j - 1] + 1; 33 a[1][i][j] = a[1][i - 1][j - 1] + 1; 34 a[2][i][j] = a[2][i - 1][j ] + 1; 35 a[3][i][j] = a[3][i - 1][j + 1] + 1; 36 } 37 else 38 a[0][i][j] = a[1][i][j] = a[2][i][j] = a[3][i][j] = 0; 39 for (int i = n; i >= 1; --i) 40 for (int j = n; j >= 1; --j) 41 if (s[i][j]){ 42 a[4][i][j] = a[4][i ][j + 1] + 1; 43 a[5][i][j] = a[5][i + 1][j + 1] + 1; 44 a[6][i][j] = a[6][i + 1][j ] + 1; 45 a[7][i][j] = a[7][i + 1][j - 1] + 1; 46 } 47 else 48 a[4][i][j] = a[5][i][j] = a[6][i][j] = a[7][i][j] = 0; 49 double ans = -1.0; 50 int x = 0, y = 0, z = 0; 51 for (int i = 1; i <= n; ++i) 52 for (int j = 1; j <= n; ++j){ 53 if (!s[i][j]) 54 continue; 55 56 int l = min(min(a[0][i][j], a[2][i][j]), min(a[4][i][j], a[6][i][j])); 57 double res = p[0][i][j + l - 1] - p[0][i][j - l] + p[2][i + l - 1][j] - p[2][i - l][j] - val[s[i][j]]; 58 if (ans < res) 59 ans = res, x = i, y = j, z = l; 60 l = min(min(a[1][i][j], a[3][i][j]), min(a[5][i][j], a[7][i][j])); 61 res = p[1][i + l - 1][j + l - 1] - p[1][i - l][j - l] + p[3][i + l - 1][j - l + 1] - p[3][i - l][j + l] - val[s[i][j]]; 62 if (ans < res) 63 ans = res, x = i, y = j, z = -l; 64 } 65 if (ans < 0.) 66 puts("0"); 67 else if (z > 0){ 68 unsigned ans = s[x][y]; 69 for (int i = -z + 1; i < z; ++i) 70 if (i){ 71 ans = ans * s[x][y + i] % MOD; 72 ans = ans * s[x + i][y] % MOD; 73 } 74 printf("%u\n", ans); 75 } 76 else{ 77 unsigned ans = s[x][y]; 78 for (int i = -z - 1; i > z; --i) 79 if (i){ 80 ans = ans * s[x + i][y + i] % MOD; 81 ans = ans * s[x + i][y - i] % MOD; 82 } 83 printf("%u\n", ans); 84 } 85 return 0; 86 }