codeforces C#264. Gargari and Bishops

2024-06-05 21:32

本文主要是介绍codeforces C#264. Gargari and Bishops,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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 getx 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 integersaij(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), wherexi is the number of the row where thei-th bishop should be placed, yi is the number of the column where thei-th bishop should be placed. Consider rows are numbered from 1 ton from top to bottom, and columns are numbered from 1 ton from left to right.

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

Sample test(s)
Input
4
1 1 1 1
2 1 1 0
1 1 1 0
1 0 0 1
Output
12
2 2 3 2
题意:给你个n*n的矩阵,对于一个点我们可以统计经过它的斜线上的值,让你选两个点,且经过的斜线是不相交的,求这两个点能组成的最大权值
思路:首先预处理出主负斜线上的值,然后就是把矩阵划分成类似国际象棋的黑白格子,分别计算黑白格子的最大值
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn = 2005;ll arr[maxn*2];
ll brr[maxn*2];
int num[maxn][maxn];int main() {int n, a;scanf("%d", &n);memset(arr, 0, sizeof(arr));memset(brr, 0, sizeof(brr));for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {scanf("%d", &num[i][j]);}for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++) {arr[i-j+n] += num[i][j];	brr[i+j] += num[i][j];}int x1, y1, x2, y2;ll Max1 = -1, Max2 = -1;for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++) {if (abs(i+j) % 2 == 0) {if (Max1 < arr[i-j+n] + brr[i+j] - num[i][j]) {Max1 = arr[i-j+n] + brr[i+j] - num[i][j];x1 = i, y1 = j;}}if (abs(i+j) % 2 == 1) {if (Max2 < arr[i-j+n] + brr[i+j] - num[i][j]) {Max2 = arr[i-j+n] + brr[i+j] - num[i][j];x2 = i, y2 = j;}}}cout << Max1+Max2 << endl;printf("%d %d %d %d\n", x1, y1, x2, y2);return 0;
}


这篇关于codeforces C#264. Gargari and Bishops的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1034225

相关文章

2. c#从不同cs的文件调用函数

1.文件目录如下: 2. Program.cs文件的主函数如下 using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using System.Windows.Forms;namespace datasAnalysis{internal static

C#实战|大乐透选号器[6]:实现实时显示已选择的红蓝球数量

哈喽,你好啊,我是雷工。 关于大乐透选号器在前面已经记录了5篇笔记,这是第6篇; 接下来实现实时显示当前选中红球数量,蓝球数量; 以下为练习笔记。 01 效果演示 当选择和取消选择红球或蓝球时,在对应的位置显示实时已选择的红球、蓝球的数量; 02 标签名称 分别设置Label标签名称为:lblRedCount、lblBlueCount

用命令行的方式启动.netcore webapi

用命令行的方式启动.netcore web项目 进入指定的项目文件夹,比如我发布后的代码放在下面文件夹中 在此地址栏中输入“cmd”,打开命令提示符,进入到发布代码目录 命令行启动.netcore项目的命令为:  dotnet 项目启动文件.dll --urls="http://*:对外端口" --ip="本机ip" --port=项目内部端口 例: dotnet Imagine.M

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内

题目点击打开链接 凸多边形A, 多边形B, 判断B是否严格在A内。  注意AB有重点 。  将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。 或者说B上的某点在凸包的边上则也说明B不严格在A里面。 这个处理有个巧妙的方法,只需在求凸包的时候, <=  改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。 另外不能去重点。 int

Codeforces 482B 线段树

求是否存在这样的n个数; m次操作,每次操作就是三个数 l ,r,val          a[l] & a[l+1] &......&a[r] = val 就是区间l---r上的与的值为val 。 也就是意味着区间[L , R] 每个数要执行 | val 操作  最后判断  a[l] & a[l+1] &......&a[r] 是否= val import ja

C# dateTimePicker 显示年月日,时分秒

dateTimePicker默认只显示日期,如果需要显示年月日,时分秒,只需要以下两步: 1.dateTimePicker1.Format = DateTimePickerFormat.Time 2.dateTimePicker1.CustomFormat = yyyy-MM-dd HH:mm:ss Tips:  a. dateTimePicker1.ShowUpDown = t

C#关闭指定时间段的Excel进程的方法

private DateTime beforeTime;            //Excel启动之前时间          private DateTime afterTime;               //Excel启动之后时间          //举例          beforeTime = DateTime.Now;          Excel.Applicat