当前位置:网站首页>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
边栏推荐
- Redis入门完整教程:复制拓扑
- INS/GPS组合导航类型简介
- QT常见概念-1
- 从零安装Redis
- Kysl Haikang camera 8247 H9 ISAPI test
- 知识图谱构建全流程
- MOS transistor realizes the automatic switching circuit of main and auxiliary power supply, with "zero" voltage drop and static current of 20ua
- Read fast RCNN in one article
- Summary of research status of inertial navigation calibration at home and abroad (abridged version)
- Have fun | latest progress of "spacecraft program" activities
猜你喜欢

Uniapp adaptation problem

leetcode-02(链表题)

Redis getting started complete tutorial: replication topology

Read fast RCNN in one article
MySQL提升大量数据查询效率的优化神器

杰理之在非蓝牙模式下,手机连接蓝牙不要跳回蓝牙模式处理方法【篇】
Django database (SQLite) basic introductory tutorial

Change your posture to do operation and maintenance! GOPs 2022 Shenzhen station highlights first!

杰理之播内置 flash 提示音控制播放暂停【篇】

How to write test cases for test coupons?
随机推荐
2022 spring recruitment begins, and a collection of 10000 word interview questions will help you
Planning and design of double click hot standby layer 2 network based on ENSP firewall
Redis getting started complete tutorial: client management
The whole process of knowledge map construction
uniapp的表单验证
杰理之FM 模式单声道或立体声选择设置【篇】
尚硅谷JVM-第一章 类加载子系统
Form validation of uniapp
【2022国赛模拟】多边形——计算几何、二分答案、倍增
Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands
QT常见概念-1
LeetCode 77:组合
Leetcode 77: combination
A complete tutorial for getting started with redis: AOF persistence
Cryptography series: detailed explanation of online certificate status protocol OCSP
Examples of how to use dates in Oracle
凌云出海记 | 易点天下&华为云:推动中国电商企业品牌全球化
Unity使用MaskableGraphic画一条带箭头的线
MySQL is an optimization artifact to improve the efficiency of massive data query
Es6中Promise的使用