当前位置:网站首页>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 language exercises_ one
- What are the applications and benefits of MES management system
- Redis getting started complete tutorial: client management
- MOS transistor realizes the automatic switching circuit of main and auxiliary power supply, with "zero" voltage drop and static current of 20ua
- sshd[12282]: fatal: matching cipher is not supported: [email protected] [preauth]
- 左程云 递归+动态规划
- 杰理之FM 模式单声道或立体声选择设置【篇】
- Hash table and full comments
- How does C language (string) delete a specified character in a string?
- Don't you know the relationship between JSP and servlet?
猜你喜欢
uniapp适配问题
【Socket】①Socket技术概述
上个厕所的功夫,就把定时任务的三种调度策略说得明明白白
[secretly kill little partner pytorch20 days] - [Day1] - [example of structured data modeling process]
Hash table and full comments
Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (time synchronization part)
centerX: 用中国特色社会主义的方式打开centernet
Install redis from zero
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
Django数据库(SQlite)基本入门使用教程
随机推荐
PSINS中19维组合导航模块sinsgps详解(初始赋值部分)
Centerx: open centernet in the way of socialism with Chinese characteristics
The solution of unable to create servlet file after idea restart
Classify the features of pictures with full connection +softmax
What are the applications and benefits of MES management system
2022 spring recruitment begins, and a collection of 10000 word interview questions will help you
2022年信息安全工程师考试大纲
The 8 element positioning methods of selenium that you have to know are simple and practical
Form validation of uniapp
MySQL is an optimization artifact to improve the efficiency of massive data query
Es6中Promise的使用
QT common Concepts-1
Redis入门完整教程:复制配置
Metaforce force meta universe fossage 2.0 smart contract system development (source code deployment)
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
杰理之关于 DAC 输出功率问题【篇】
Digital scrolling increases effect
首届“量子计算+金融科技应用”研讨会在京成功举办
Have fun | latest progress of "spacecraft program" activities
Redis入門完整教程:問題定比特與優化