two bishops on the chessboard (CodeForce 463C)

啦啦啦,先来看一看题目!

Description

Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.

He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.

We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).

Input

The first line contains a single integer n(2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij(0 ≤ aij ≤ 109) — description of the chessboard.

Output

On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2(1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right.

If there are several optimal solutions, you can print any of them.

Sample Input

Input
4
1 1 1 1
2 1 1 0
1 1 1 0
1 0 0 1
Output
12
2 2 3 2
恩!你看懂题了吗??反正,我刚开始是没看懂。。。/(ㄒoㄒ)/~~

好,我们来运用强大的百度翻译来看看题意。

题意大致是这样的:给你一个nxn的棋盘,每格上面有一个数字,代表多少dollar、然后有两个棋子,让你放在棋盘上,这个棋子的主对角线和副对角线的格子都是它的感攻击范围,所以上面的dollar都是它的。但是呢,两个棋子的攻击范围不能重叠,意思就是他们的对角线不能相交。问你怎么放这两个棋子,才能使他们相加的钱最大?最多多少钱?这两个棋子放的坐标是多少?

大致思路:首先,我们来预处理每一个对角线,求出它的总共钱是多少、

因为题目要求两个棋子的攻击范围不能重叠,所以我们想如何他们才能不重叠呢?结果,有一个规律就是当这两个棋子的x和y坐标相加之后奇偶性不同,即x1+y1与x2+y2的奇偶不同!

这个时候,我们就只需要枚举满足这种情况的两个点,算出他们的总共钱是多少?求最大!

但是!!!你需要注意当你算棋子能拿到多少钱的时候,将主副对角线的钱相加之后,要再减去那个点的钱、因为两条对角线相交,交点相当于计算了两次!

你应该懂了吧。

代码如下:

本人大水比一枚、如代码有问题,请积极指正、

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;

#define ll long long
#define nn 2010
ll mp[nn][nn];
ll s1[nn*2];//副对角线
ll s2[nn*2];//主对角线
void init()
{
    memset(s1,0,sizeof(s1));
    memset(s2,0,sizeof(s2));
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        init();
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                scanf("%lld",&mp[i][j]);
                s1[i+j]+=mp[i][j];
                s2[i-j+n]+=mp[i][j];
            }
        }
        int x1=1,y1=1,x2=1,y2=2;
        ll max1=0,max2=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                ll tmp=s1[i+j]+s2[i-j+n]-mp[i][j];
                if((i+j)%2==0 && tmp > max1)
                {
                    max1=tmp;
                    x1=i;
                    y1=j;
                }
                if((i+j)%2==1 && tmp > max2)
                {
                    max2 = tmp;
                    x2=i;
                    y2=j;
                }
            }
        }
        printf("%lld\n",max1+max2);
        printf("%d %d %d %d\n",x1+1,y1+1,x2+1,y2+1);
    }
    return 0;
}
yeah!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值