codeforces 463C Gargari and Bishops
这个题, 最主要的应该是找到对角线上的格子的关系。 “ \" 这种对角线, 关系是x-y+n相等, ” / “ 这种, 关系是x+y相等。知道每个格子的两种对角线的值, 那么这个格子的值可以表示为d1[x+y]+d2[x-y+n]-a[x][y], a[x][y]是初值。 知道这个以后就好做了。
具体可以看这里http://blog.csdn.net/kenden23/article/details/38959141.....
#include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
ll a[][], d1[], d2[];
int ans[][];
int main()
{
int n;
cin>>n;
for(int i = ; i<n; i++) {
for(int j = ; j<n; j++) {
scanf("%d", &a[i][j]);
d1[i+j] += a[i][j];
d2[i-j+n] += a[i][j];
}
}
for(int i = ; i<n; i++) {
for(int j = ; j<n; j++) {
a[i][j] = d1[i+j]+d2[i-j+n]-a[i][j];
}
}
ans[][] = ans[][] = ans[][] = ;
ans[][] = ;
for(int i = ; i<n; i++) {
for(int j = ; j<n; j++) {
if((i+j)&) {
if(a[i][j]>a[ans[][]][ans[][]]) {
ans[][] = i;
ans[][] = j;
}
} else {
if(a[i][j]>a[ans[][]][ans[][]]) {
ans[][] = i;
ans[][] = j;
}
}
}
}
cout<<a[ans[][]][ans[][]]+a[ans[][]][ans[][]]<<endl;
cout<<ans[][]+<<" "<<ans[][]+<<" "<<ans[][]+<<" "<<ans[][]+<<endl;
}
codeforces 463C Gargari and Bishops的更多相关文章
- codeforces 463C. Gargari and Bishops 解题报告
题目链接:http://codeforces.com/contest/463/problem/C 题目意思:要在一个 n * n 大小的棋盘上放置两个bishop,bishop可以攻击的所有位置是包括 ...
- Codeforces 463C Gargari and Bishops 题解
题目出处: http://codeforces.com/contest/463/problem/C 感觉本题还是挺难的.须要好好总结一下. 计算对角线的公式: 1 右斜对角线,也叫主对角线的下标计算公 ...
- 【CodeForces】Gargari and Bishops
依据贪心能够知道,放置的教主必须不能相互攻击到(也就是不在一条对角线上)才干够使得结果最大化. 依据观察能够得到教主相互不攻击的条件是他的坐标和互为奇偶(x + y) 之后直接暴力,处理每一个坐标对角 ...
- CodeForces463C Gargari and Bishops(贪心)
CodeForces463C Gargari and Bishops(贪心) CodeForces463C 题目大意: 在国际象棋的棋盘上放两个主教,这个两个主教不能攻击到同一个格子,最后的得分是这 ...
- codeforces Gargari and Bishops(很好的暴力)
/* 题意:给你一个n*n的格子,每一个格子都有一个数值!将两只bishops放在某一个格子上, 每一个bishop可以攻击对角线上的格子(主对角线和者斜对角线),然后会获得格子上的 数值(只能获取一 ...
- Codeforces Round #264 (Div. 2) C. Gargari and Bishops 主教攻击
http://codeforces.com/contest/463/problem/C 在一个n∗n的国际象棋的棋盘上放两个主教,要求不能有位置同时被两个主教攻击到,然后被一个主教攻击到的位置上获得得 ...
- Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】
称号: 意甲冠军:给定一个矩阵,每格我们有一个数,然后把两个大象,我希望能够吃的对角线上的所有数字.我问两个最大的大象可以吃值. 分析:这种想法是暴力的主题,计算出每一格放象的话能得到多少钱,然后求出 ...
- Codeforces 463D Gargari and Permutations
http://codeforces.com/problemset/problem/463/D 题意:给出k个排列,问这k个排列的最长公共子序列的长度. 思路:只考虑其中一个的dp:f[i]=max(f ...
- Codeforces 463D Gargari and Permutations(求k个序列的LCS)
题目链接:http://codeforces.com/problemset/problem/463/D 题目大意:给你k个序列(2=<k<=5),每个序列的长度为n(1<=n< ...
随机推荐
- jQuery源码笔记——四
each()实现 var jQuery = function( selector, context ) { return new jQuery.fn.init( selector, context ) ...
- android的Home键的监听封装工具类(一)
android的Home键的监听封装: package com.gzcivil.utils; import android.content.BroadcastReceiver; import andr ...
- C#用网易邮箱发送邮件(同步异步)
SmtpClient smtpServer = new SmtpClient("smtp.163.com"); smtpServer.Port = ; smtpServer.Cre ...
- C# - ADO.Net 调用存储过程
------------------------存储过程调用,创建DataSet:----------------------//数据库连接字符串string connStr = @"Dat ...
- css透明背景兼容方案
css透明是一个技术活,因为这里面涉及到了IE8及以下版本不兼容opacity这个css3属性,而filter:alpha(opacity=80)这个值则是不兼容IE6.网上比较流行的透明css是这样 ...
- 页面类跳转Demo
package baidumapsdk.demo; import android.app.Activity; import android.content.BroadcastReceiver; imp ...
- java泛型问题 关于警告:XX is a raw type
(本文例子适用于JDK 5.0, 学习请先安装并配置!!!) 我们从一个简单的例子开始:假设我们现在需要一个专用来存储字符串的List,该如何实现?呵呵,这还不简单,且看如下代码: ...
- 《转》读discuzx3.1 数据库层笔记
最近开始在看discuzx3.1的代码,看到数据库层的实现,discuzx的数据库层能够支撑数据库分库,分布式部署,主要水平分表,也可以很方便的支持其他数据库.性能上,可以做读写分离,支持数据缓存.可 ...
- J2SE知识点摘记(二十二)
Map 1.4.1 概述 数学中的映射关系在Java中就是通过Map来实现的.它表示,里面存储的元素是一个对(pair),我们通过一个对象,可以在这个映射关系中找到另外一个和这个对象相关 ...
- C++ 下 typeof 的实现
现在我们有这样一坨代码: std::vector<int> arr; // ... for(std::vector<int>::iterator iter = arr.begi ...