当前位置:网站首页>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
边栏推荐
- Matlb| economic scheduling with energy storage, opportunity constraints and robust optimization
- Mmdetection3d loads millimeter wave radar data
- leetcode-02(链表题)
- Django database (SQLite) basic introductory tutorial
- 杰理之在非蓝牙模式下,手机连接蓝牙不要跳回蓝牙模式处理方法【篇】
- 2022 information security engineer examination outline
- Unity uses maskablegraphic to draw a line with an arrow
- PSINS中19维组合导航模块sinsgps详解(滤波部分)
- Leetcode 77: combination
- 掘金量化:通过history方法获取数据,和新浪财经,雪球同用等比复权因子。不同于同花顺
猜你喜欢

商城商品的知识图谱构建

Redis getting started complete tutorial: replication configuration

Redis入门完整教程:复制拓扑

A complete tutorial for getting started with redis: problem location and optimization

Redis getting started complete tutorial: client management

mos管實現主副電源自動切換電路,並且“零”壓降,靜態電流20uA

又一百万量子比特!以色列光量子初创公司完成1500万美元融资

Uniapp adaptation problem

mos管实现主副电源自动切换电路,并且“零”压降,静态电流20uA

【Socket】①Socket技术概述
随机推荐
Cryptography series: detailed explanation of online certificate status protocol OCSP
Kysl Haikang camera 8247 H9 ISAPI test
Static proxy of proxy mode
Hash table and full comments
The whole process of knowledge map construction
Examples of how to use dates in Oracle
A complete tutorial for getting started with redis: RDB persistence
Kubernetes source code analysis (II) -- resource
How-PIL-to-Tensor
Dotconnect for DB2 Data Provider
Unity custom webgl packaging template
How to write test cases for test coupons?
c语言字符串排序
Google Earth engine (GEE) -- 1975 dataset of Landsat global land survey
How to verify accesstoken in oauth2 protocol
Error in fasterxml tostringserializerbase
Have fun | latest progress of "spacecraft program" activities
杰理之播内置 flash 提示音控制播放暂停【篇】
uniapp适配问题
How does C language (string) delete a specified character in a string?