当前位置:网站首页>Codeforces round 264 (Div. 2) C gargari and Bishop [violence]
Codeforces round 264 (Div. 2) C gargari and Bishop [violence]
2022-07-07 03:10:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack
The title of :
Serie A Champion : Given a matrix , We have a number in each grid , Then put two elephants , I hope to be able to eat all the numbers on the diagonal . I asked the two biggest elephants what they could eat .
analysis : This idea is the subject of violence , Calculate how much money you can get for each grid , Then find two non conflicting maxima . The method I wrote during the competition is to find out each value first , Number and save it in the array , Then through a series of processing , In short, it's very troublesome . For more than an hour . Finally, I found a little mistake , There's no time . The initial example also failed .
Then I read what others wrote , It's too simple . You can find it directly by using the sum and difference of rows and columns . It seems that the code ability still needs to be improved .
my AC Code :
#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;
}
Copyright notice : This article is the original article of the blogger , Blog , Do not reprint without permission .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116787.html Link to the original text :https://javaforall.cn
边栏推荐
- Oracle connection pool is not used for a long time, and the connection fails
- 从控制理论的角度谈数据分析
- How to verify accesstoken in oauth2 protocol
- How to design interface test cases? Teach you a few tips to draft easily
- Software testing -- common assertions of JMeter interface testing
- 杰理之播内置 flash 提示音控制播放暂停【篇】
- Centerx: open centernet in the way of socialism with Chinese characteristics
- New benchmark! Intelligent social governance
- How to analyze fans' interests?
- 「小样本深度学习图像识别」最新2022综述
猜你喜欢
The first symposium on "quantum computing + application of financial technology" was successfully held in Beijing
Change your posture to do operation and maintenance! GOPs 2022 Shenzhen station highlights first!
Intelligent static presence detection scheme, 5.8G radar sensing technology, human presence inductive radar application
uniapp适配问题
C language exercises_ one
Redis introduction complete tutorial: client case analysis
Read fast RCNN in one article
Development of wireless communication technology, cv5200 long-distance WiFi module, UAV WiFi image transmission application
How to analyze fans' interests?
tensorboard的使用
随机推荐
杰理之播内置 flash 提示音控制播放暂停【篇】
“零售为王”下的家电产业:什么是行业共识?
Cocos2d-x Box2D物理引擎编译设置
Redis introduction complete tutorial: replication principle
netperf 而网络性能测量
Cryptography series: detailed explanation of online certificate status protocol OCSP
硬件之OC、OD、推挽解释
Form validation of uniapp
Django database (SQLite) basic introductory tutorial
Contribution of Writing Series
腾讯云原生数据库TDSQL-C入选信通院《云原生产品目录》
How-PIL-to-Tensor
迷失在MySQL的锁世界
[socket] ① overview of socket technology
New benchmark! Intelligent social governance
Andrews - multimedia programming
A complete tutorial for getting started with redis: RDB persistence
Software testing -- common assertions of JMeter interface testing
How to verify accesstoken in oauth2 protocol
杰理之RTC 时钟开发【篇】