当前位置:网站首页>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
边栏推荐
- How to write test cases for test coupons?
- The solution of unable to create servlet file after idea restart
- 掘金量化:通过history方法获取数据,和新浪财经,雪球同用等比复权因子。不同于同花顺
- Redis getting started complete tutorial: common exceptions on the client
- Install redis from zero
- The whole process of knowledge map construction
- Left path cloud recursion + dynamic planning
- 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?
- Left value, right value
- Simple bubble sort
猜你喜欢
What are the characteristics of the operation and maintenance management system
MySQL is an optimization artifact to improve the efficiency of massive data query
Django数据库(SQlite)基本入门使用教程
Uniapp adaptation problem
Es6中Promise的使用
input_delay
Redis getting started complete tutorial: client management
uniapp的表单验证
Oauth2协议中如何对accessToken进行校验
首届“量子计算+金融科技应用”研讨会在京成功举办
随机推荐
凌云出海记 | 易点天下&华为云:推动中国电商企业品牌全球化
DOMContentLoaded和window.onload
如何分析粉丝兴趣?
Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (time synchronization part)
Metaforce force meta universe fossage 2.0 smart contract system development (source code deployment)
SQL中删除数据
QT common Concepts-1
新标杆!智慧化社会治理
SQL Tuning Advisor一个错误ORA-00600: internal error code, arguments: [kesqsMakeBindValue:obj]
[secretly kill little partner pytorch20 days] - [Day1] - [example of structured data modeling process]
左程云 递归+动态规划
Contribution of Writing Series
杰理之开 BLE 退出蓝牙模式卡机问题【篇】
Use of tensorboard
商城商品的知识图谱构建
QT Bluetooth: qbluetooth DeviceInfo
【2022国赛模拟】多边形——计算几何、二分答案、倍增
Left path cloud recursion + dynamic planning
Shell 编程基础
2022 information security engineer examination outline