当前位置:网站首页>-采花生-
-采花生-
2022-08-09 23:46:00 【-JMY-】
题目描述
在参加“采花生”这个项目比赛时,考官会出示一块n行、m列的花生田,上面一共种了n*m株花生苗。每株花生植株下都结了一定数量的花生果,比赛开始时选手站在第1行,第1列的位置,现要求用最短的时间找到结花生果最多的一株花生植株(数据保证花生果最多的植株只有一株),然后按先向南(下)走,再向东(右)的路线顺序去采摘它的花生果,沿路经过的其他花生植株下面的花生果也要一并采摘下来,但不允许采摘没有路过的花生植株,否则依犯规出局处理。问这个选手一共可以采摘到多少粒花生果?
如一块n=5,m=6的花生田
第1列 第2列 第3列 第4列 第5列 第6列
第1行 5 7 4 5 1 13
第2行 9 6 3 2 8 7
第3行 10 14 0 1 9 4
第4行 4 6 9 18 25 0
第5行 3 1 2 9 0 2
可以发现结花生果最多的那株花生植株在(4,5),则选手采摘的顺序应为(1,1)-(2,1)-(3,1)-(4,1)-(4,2)-(4,3)-(4,4)-(4,5),一共采得的花生果粒数为5+9+10+4+6+9+18+25=86。
输入
第1行有两个整数n和m( 1 < n,m <= 100 ),表示花生田一共有n行m列。
第2至n+1行,每行有m个用空格隔开的整数,第i + 1行的第j个整数Pij(0 <= Pij <= 700)表示花生田里植株(i, j)下花生的数目,0表示该植株下没有花生。
输出
只有一行,一个整数,表示选手一共摘到的花生果数目。
样例输入
5 6 5 7 4 5 1 13 9 6 3 2 8 7 10 14 0 1 9 4 4 6 9 18 25 0 3 1 2 9 0 2
样例输出
86
参考代码:
#include<bits/stdc++.h>
using namespace std;
int n,m,a[105][105],x,y,s,maxn;
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&a[i][j]);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(a[i][j]>maxn){
maxn=a[i][j];
x=j+1;
y=i+1;
}
for(int i=0;i<y;i++)
s+=a[i][0];
for(int i=1;i<x;i++)
s+=a[y-1][i];
printf("%d",s);
return 0;
}
边栏推荐
- Spark基础【RDD单Value类型转换算子】
- [C language] Address book "Static Memory Version"
- The technical aspects of the byte have been passed, and the salary has been negotiated for 20K*13, but the result is still being brushed. I asked the HR why...
- 技术分享 | 接口自动化测试如何处理 Header cookie
- 02|运算符
- 深度剖析 Apache EventMesh 云原生分布式事件驱动架构
- Description of AirFlow
- 【「收藏」Oracle 数据库安装】
- 共创 Ray 中文社区,Ray Forward Meetup 2022 直播邀你参加!
- GoLang 使用 goroutine 停止的几种办法
猜你喜欢

基于FPGA的任意字节数的串口接收(含源码工程)

Why don't suggest you run in Docker Mysql?

【CAS:41994-02-9 |Biotinyl tyramide】生物素基酪氨酰胺价格

算法---整数替换(Kotlin)

WPF DataGrid 使用数据模板

Today's sleep quality record 61 points

最高月薪15K,谁有历经千辛万苦的意志,谁就能收获属于自己的成功~

为什么不建议你在 Docker 中跑 Mysql ?

Next.js获取路由参数及styled-jsx 的使用

Project (7) - PolarSeg point cloud semantic segmentation
随机推荐
E - Sugoroku 3(期望dp)
ES6 Beginner to Mastery #13: Extension Methods for Arrays 2
【「收藏」Oracle 数据库安装】
vmware Exsi 网卡配置
Kubernetes服务接入Istio
微信公众号如何开通支付功能?
ES6 Beginner to Mastery #15: Generator Usage
arm-4-裸板开发
大龄测试员刚迈过了 35 岁这个“坎儿”,和大家说点儿心里话
Pinduoduo store operation must know to leave a little knowledge of operation
错误提示:Syntax error on token “function”, delete this token
Service Discovery @EnableDiscoveryClient
Today's sleep quality record 61 points
Distributed database problem (3): data consistency
PEG 衍生物Biotin-PEG1-OH(cas:95611-10-2,2-生物素氨基乙醇)优势说明
redis distributed lock code example
[NCTF2019]True XML cookbook-1|XXE漏洞
3.11-程序基本的控制语句 3.12-表达式 3.13-数据类型 3.14-常量/变量 3.15-标识符
C语言学习之旅 【操作符(残缺版)】
[SUCTF 2019]CheckIn (.htaccess和.user.ini)