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. Markdown——入门指南

    导语: Markdown 是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿者广泛使用.看到这里请不要被「标记」.「语言」所迷惑,Markdown 的语法十分简单.常用的标记 ...

  2. 08--STL关联容器(set/multiset)

    一:set/multiset的简介 set是一个集合容器,其中所包含的元素是唯一的,集合中的元素按一定的顺序排列.元素插入过程是按排序规则插入,所以不能指定插入位置. set采用红黑树变体的数据结构实 ...

  3. MongoDB用户权限认证

    关于用户的认证及权限 用户是跟着库创建的,在哪个库创建的什么权限的什么用户,只对此库有相应权限(除超级管理员以外). 官网文档:https://docs.mongodb.com/master/refe ...

  4. Apicloud学习第三天——获取云数据库的数据方法

    apicloud学习30天中的对用进行注册和登录以及数据的获取的代码,在apicloud中有单独的api对用户的增删查改进行操作,这里写下增加和查询. 增加用户数据 var model=api.req ...

  5. Ps 应用小技巧总结

    一.如何等比例放大图片? 使用形状工具,画图之后,保存为智能对象,但是 ctrl+T 之后放大,会有虚边: 解决办法:编辑智能对象,在新的画布中:图像---图像大小----ctrl+alt+I 此处进 ...

  6. (Python2)自动对话机器人 代码

    dict = { 'hello': 'hello'}flag = 'c'work = Trueprint 'hi,my name is python.'print 'do you want chat ...

  7. Luogu P1082 同余方程(NOIP 2012) 题解报告

    题目传送门 [题目大意] 求关于x的同余方程 ax≡1(mod b)的最小整数解. [思路分析] 由同余方程的有关知识可得,ax≡1(mod b)可以化为ax+by=1,此方程有解当且仅当gcd(a, ...

  8. vue路由--网站导航功能

    1.首先需要按照Vue router支持 npm install vue-router然后需要在项目中引入: import Vue from 'vue' import VueRouter from ' ...

  9. [经验交流] kubeadm 安装 kubernetes 一年过期的解决办法

    kubeadm 是 kubernetes 提供的一个初始化集群的工具,使用起来非常方便.但是它创建的apiserver.controller-manager等证书默认只有一年的有效期,同时kubele ...

  10. [笔记]猿计划(WEB安全工程师养成之路系列教程):03HTML基础标签

    1.<!DOCTYPE>声明 <!DOCTYPE> 不是 HTML 标签.它为浏览器提供一项信息(声明),即 HTML 是用什么版本编写的. 2.HTML不区分大小写 3.标签 ...