G - Gargari and Bishops-贪心暴力

102 篇文章 0 订阅
70 篇文章 0 订阅

 

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <Map>
#include <set>
#include <vector>
using namespace std;
int n;  
__int64 tm[2005][2005];
__int64 L[2005*2];//副对角线元素之和 
__int64 R[2005*2]; //主对角线元素之和  

int main()
{  
	__int64 i,j;
	cin>>n; 

	
	for (i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf("%I64d",&tm[i][j]);
			L[i+j]	 +=tm[i][j];//同一条副对角线i+j相同  
			R[i-j+n] +=tm[i][j];//同一条主对角线i-j相同
		} 
	} 
	int rx=1;
	int ry=1;
	int x1=1;
	int y1=2;
	__int64 max2=0;
	__int64 max1=0;
	__int64 tmp=0;
	for (i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			tmp=L[i+j]+R[i-j+n]-tm[i][j];
			
			if ((i+j)%2==0 && tmp>max1)
			{
				
				max1=tmp;
				x1=i;
				y1=j;
				
			}
			if ((i+j)%2==1 && tmp>max2)
			{
				
				max2=tmp;
				rx=i;
				ry=j;
				
			}
		}
	}
	
	printf("%I64d\n", max1 + max2); 
	printf("%d %d %d %d\n",x1,y1,rx,ry);
	
	
	return 0;
	
}

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).





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值