Vanya and Balloons

枚举中心去更新答案, 数字过大用log去比较, 斜着的旋转一下坐标, 然后我旋出来好多bug。。。。

#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0); using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < ) a += mod;}
template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;} int power(int a, int b) {
int ans = ;
while(b) {
if(b & ) ans = 1LL * ans * a % mod;
a = 1LL * a * a % mod; b >>= ;
}
return ans;
} int n, a[N][N], b[N][N];
short row[N][N][], col[N][N][];
short L[N][N], R[N][N], U[N][N], D[N][N];
bool vis[N][N]; LD lg2 = logl(), lg3 = logl(); bool cmp(const PII& a, const PII& b) {
return a.fi * lg2 + a.se * lg3 < b.fi * lg2 + b.se * lg3;
} inline int calcRow(int i, int l, int r, int op) {
return row[i][r][op] - row[i][l][op];
}
inline int calcCol(int j, int l, int r, int op) {
return col[j][r][op] - col[j][l][op];
} PII calc(int a[N][N], int n) {
PII ans = mk(, );
for(int i = ; i <= n; i++) {
for(int j = ; j <= n; j++) {
if(!a[i][j]) L[i][j] = j, U[i][j] = i;
else L[i][j] = L[i][j - ], U[i][j] = U[i - ][j];
row[i][j][] = row[i][j - ][] + (a[i][j] == );
row[i][j][] = row[i][j - ][] + (a[i][j] == );
col[j][i][] = col[j][i - ][] + (a[i][j] == );
col[j][i][] = col[j][i - ][] + (a[i][j] == );
}
}
for(int i = n; i >= ; i--) {
for(int j = n; j >= ; j--) {
if(!a[i][j]) R[i][j] = j, D[i][j] = i;
else {
if(j == n) R[i][j] = j + ;
else R[i][j] = R[i][j + ];
if(i == n) D[i][j] = i + ;
else D[i][j] = D[i + ][j];
}
}
}
for(int i = ; i <= n; i++) {
for(int j = ; j <= n; j++) {
if(!a[i][j] || !vis[i][j]) continue;
int d = min({i - U[i][j], D[i][j] - i, j - L[i][j], R[i][j] - j});
PII tmp = mk(, );
tmp.fi += calcRow(i, j - d, j + d - , );
tmp.fi += calcCol(j, i - d, i + d - , );
tmp.se += calcRow(i, j - d, j + d - , );
tmp.se += calcCol(j, i - d, i + d - , );
if(a[i][j] == ) tmp.fi--;
else if(a[i][j] == ) tmp.se--;
if(cmp(ans, tmp)) {
ans = tmp;
}
}
}
return ans;
} int main() {
int mask = ;
scanf("%d", &n);
for(int i = ; i <= n; i++)
for(int j = ; j <= n; j++)
scanf("%1d", &a[i][j]), vis[i][j] = true, mask |= a[i][j];
if(!mask) return puts(""), ;
PII ret1 = calc(a, n);
for(int i = ; i <= * n; i++)
for(int j = ; j <= * n; j++)
b[i][j] = , vis[i][j] = false;
for(int i = ; i <= n; i++)
for(int j = ; j <= n; j++)
b[i - j + n][i + j + n] = a[i][j], vis[i - j + n][i + j + n] = true;
int lx = - + n, ly = + + n;
int rx = n - n + n, ry = n + n + n;
int x = (lx + rx) / , y = (ly + ry) / ;
int d = abs(x - lx) + abs(y - ry);
for(int i = ; i <= * n; i++)
for(int j = ; j <= * n; j++)
if(abs(i - x) + abs(j - y) > d)
b[i][j] = ;
PII ret2 = calc(b, * n);
if(cmp(ret1, ret2)) {
printf("%d\n", 1LL * power(, ret2.fi) * power(, ret2.se) % mod);
} else {
printf("%d\n", 1LL * power(, ret1.fi) * power(, ret1.se) % mod);
}
return ;
} /*
*/

Codeforces 677E Vanya and Balloons的更多相关文章

  1. Codeforces 677E Vanya and Balloons(DP + 一些技巧)

    题目大概说给一张地图,地图每个格子都有0到9中的某一个数字.现在要在一个格子放炸弹,炸弹爆炸后水柱有两种扩展方式,一种是上.下.左.右,另一种是左上.右下.右上.左下,且四个方向的长度都一样.问放哪个 ...

  2. codeforces 492E. Vanya and Field(exgcd求逆元)

    题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走 ...

  3. Codeforces 677D Vanya and Treasure 暴力+BFS

    链接 Codeforces 677D Vanya and Treasure 题意 n*m中有p个type,经过了任意一个 type=i 的各自才能打开 type=i+1 的钥匙,最初有type=1的钥 ...

  4. E. Vanya and Balloons Codeforces Round #355 (Div. 2)

    http://codeforces.com/contest/677/problem/E 题意:有n*n矩形,每个格子有一个值(0.1.2.3),你可以在矩形里画一个十字(‘+’形或‘x’形),十字的四 ...

  5. CodeForces 552C Vanya and Scales

    Vanya and Scales Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u S ...

  6. Codeforces 677C. Vanya and Label 位操作

    C. Vanya and Label time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  7. CodeForces - 552E Vanya and Brackets

    Vanya and Brackets Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u ...

  8. codeforces C. Vanya and Scales

    C. Vanya and Scales Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w10 ...

  9. codeforces 492B. Vanya and Lanterns 解题报告

    题目链接:http://codeforces.com/problemset/problem/492/B #include <cstdio> #include <cstdlib> ...

随机推荐

  1. 构建之法助教园地第一次作业--点评<西北师范大学|李晓婷>

    一 博客点评 第一次作业--准备篇:https://www.cnblogs.com/Mookiepiece/p/10464606.html#4192515 点评内容: 首先,你对电脑很感兴趣,兴趣就是 ...

  2. 局域网配置dnsmasq

    一.安装dnsmasq centos下安装dnsmasq: yum install dnsmasq 二.配置dnsmasq: 1.编辑配置文件/etc/dnsmasq.conf # 配置上行DNS,对 ...

  3. 2019年最大的Flag

    2019年最大的Flag 今天是2019/1/15 我要立一个2019年的Flag:刻意的追求优秀>>>>>>>>>>>>勿以善 ...

  4. 关于4A系统(我对4A系统的维护的理解)

    4A系统 4A系统是统一安全管理平台解决方案,指认证Authentication.账号Account.授权Authorization.审计Audit,中文名称为统一安全管理平台解决方案.即将身份认证. ...

  5. Maven 学习总结 (七) 之 灵活构建

    一个优秀的构建系统必须足够灵活,他应该能够让项目在不同的环境下都能成功地构建.Maven为支持项目的灵活性,内置了三大特性,即属性.Profile和资源过滤. Maven属性 通过<proper ...

  6. JavaScript 归纳

    MDN 本文以 NodeJS 为交互解释器实验 尽量遵循 ES6 标准 javascript 重点 1.javascript 是单线程,通过 EventLoop 实现模拟异步,其中包括宏任务,微任务 ...

  7. JGUI源码:开发中遇到的问题(11)

    1.IE8下浏览器下css body边缘要留一个像素,如果不留的话,很有可能看不到最边缘的像素. 2.同一种颜色在深色背景和浅色背景下给人的感觉不一样,在深色背景下,给人感觉特别亮,所以深色背景下的颜 ...

  8. python3 练手实例8 批量命名图片

    #coding:utf-8 import os import tkinter as tk from tkinter import filedialog root = tk.Tk() root.with ...

  9. Linux环境安装jdk12-rpm

    此博客只是本人的个人学习记录,若有什么误导观看者,请不要怪我... 1.环境准备: Linux环境:Centos7 jdk版本:JavaSE12      下载地址:https://www.oracl ...

  10. LeetCode刷题-004两个排序数组的中位数

    给定两个大小为 m 和 n 的有序数组 nums1 和 nums2 . 请找出这两个有序数组的中位数.要求算法的时间复杂度为 O(log (m+n)) . 示例 1:nums1 = [1, 3]num ...