当前位置:网站首页>Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】
Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】
2022-07-06 19:37:00 【全栈程序员站长】
大家好,又见面了,我是全栈君
称号:
意甲冠军:给定一个矩阵,每格我们有一个数,然后把两个大象,我希望能够吃的对角线上的所有数字。我问两个最大的大象可以吃值。
分析:这种想法是暴力的主题,计算出每一格放象的话能得到多少钱,然后求出两个不冲突的最大值。我比赛的时候写的方法是先求出每个值,编号之后存到数组里面,然后在通过一系列处理得到,总之非常麻烦。写了一个多小时。最后才发现有一点小错误,没时间了。初始例子也没有通过。
然后看了下别人写的,太简洁了。直接用行和列和和差就能够直接求出来。看来代码能力还很有待提高啊。
我的AC代码:
#include <cstdio>
#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>
#include <stack>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
const long long N = 2200;
long long mp[N][N],num[N][N];
vector<long long> sum1,sum2;
long long n;
int main()
{
//freopen("Input.txt","r",stdin);
while(~scanf("%lld",&n))
{
for(long long i=1; i<=n; i++)
{
for(long long j=1; j<=n; j++)
scanf("%lld",&mp[i][j]);
}
for(long long i=n; i>=1; i--)
{
long long tmp=0;
for(long long x=1,y=i; x<=n; x++,y++)
{
tmp+=mp[x][y];
}
sum1.push_back(tmp);
}
for(long long i=2; i<=n; i++)
{
long long tmp=0;
for(long long x=i,y=1; x<=n; x++,y++)
tmp+=mp[x][y];
sum1.push_back(tmp);
}
for(long long i=1; i<=n; i++)
{
long long tmp=0;
for(long long x=i,y=1; x>=1; x--,y++)
{
tmp+=mp[x][y];
}
sum2.push_back(tmp);
}
for(long long i=2; i<=n; i++)
{
long long tmp=0;
for(long long x=n,y=i; y<=n; x--,y++)
tmp+=mp[x][y];
sum2.push_back(tmp);
}
memset(num,0,sizeof(num));
long long fx=1,fy=n;
for(long long i=1;i<=n;i++)
{
long long xx=fx,yy=fy;
for(long long j=1;j<=n;j++)
{
num[i][j]=sum2[xx-1]+sum1[yy-1]-mp[i][j];
xx++,yy--;
//printf("%lld ",num[i][j]);
}
fx++,fy++;
}
long long ans[3]={-1,-1};
long long x[3],y[3];
for(long long i=1;i<=n;i++)
{
for(long long j=1;j<=n;j++)
{
long long p=(i+j)%2;
if(num[i][j]>ans[p])
{
ans[p]=num[i][j];
x[p]=i,y[p]=j;
}
}
}
printf("%lld\n",ans[0]+ans[1]);
printf("%lld %lld %lld %lld\n",x[0],y[0],x[1],y[1]);
sum1.clear(),sum2.clear();
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116787.html原文链接:https://javaforall.cn
边栏推荐
- c语言字符串排序
- wzoi 1~200
- How-PIL-to-Tensor
- How does C language (string) delete a specified character in a string?
- 杰理之电话本获取【篇】
- [node learning notes] the chokidar module realizes file monitoring
- Don't you know the relationship between JSP and servlet?
- Google Earth engine (GEE) -- 1975 dataset of Landsat global land survey
- 杰理之在非蓝牙模式下,手机连接蓝牙不要跳回蓝牙模式处理方法【篇】
- 杰理之开启经典蓝牙 HID 手机的显示图标为键盘设置【篇】
猜你喜欢
首届“量子计算+金融科技应用”研讨会在京成功举办
Remember the problem analysis of oom caused by a Jap query
Change your posture to do operation and maintenance! GOPs 2022 Shenzhen station highlights first!
[socket] ① overview of socket technology
杰理之在非蓝牙模式下,手机连接蓝牙不要跳回蓝牙模式处理方法【篇】
Redis introduction complete tutorial: replication principle
Redis Getting started tutoriel complet: positionnement et optimisation des problèmes
Redis getting started complete tutorial: replication topology
Mmdetection3d loads millimeter wave radar data
Use of promise in ES6
随机推荐
密码学系列之:在线证书状态协议OCSP详解
Metaforce force meta universe fossage 2.0 smart contract system development (source code deployment)
Leetcode 77: combination
How to analyze fans' interests?
Wireshark installation
换个姿势做运维!GOPS 2022 · 深圳站精彩内容抢先看!
新标杆!智慧化社会治理
How to design interface test cases? Teach you a few tips to draft easily
Google Earth engine (GEE) -- 1975 dataset of Landsat global land survey
Redis入门完整教程:客户端案例分析
PSINS中19维组合导航模块sinsgps详解(时间同步部分)
MOS transistor realizes the automatic switching circuit of main and auxiliary power supply, with "zero" voltage drop and static current of 20ua
杰理之开启经典蓝牙 HID 手机的显示图标为键盘设置【篇】
c语言字符串排序
Remember the problem analysis of oom caused by a Jap query
Introduction to ins/gps integrated navigation type
杰理之FM 模式单声道或立体声选择设置【篇】
Starting from 1.5, build a micro Service Framework -- log tracking traceid
Shell 编程基础
Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (filtering part)