码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • ZCMU--1427: Tram(C语言)


    Description

    Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop aipassengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.

    Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.

    Input

    The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops.
    Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement.
    The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. This particularly means that a1 = 0.
    At the last stop, all the passengers exit the tram and it becomes empty.
    No passenger will enter the train at the last stop. That is, bn = 0.

    Output

    Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).

    Sample Input

    4
    0  3
    2  5
    4  2
    4  0

    Sample Output

    6
    注意点:要多组输入,不会就判WA了🤷
    解析:设每站下车a人,上车b人,每靠站之后增加人数就是b-a,所以我们每次靠站更新最大人数就ok。
    1. #include
    2. int main()
    3. {
    4. int n,m,r,a,b;
    5. while(~scanf("%d",&n)){
    6. m=0,r=0;//m记录最大人数,r记录当前车上人数
    7. while(n--){
    8. scanf("%d%d",&a,&b);
    9. r+=b-a;//增加人数
    10. if(r>m) m=r;//更新最大人数
    11. }
    12. printf("%d\n",m);
    13. }
    14. return 0;
    15. }

  • 相关阅读:
    [附源码]计算机毕业设计贵港高铁站志愿者服务平台
    C++基于Qt中QOpenGLWidget模块实现的画图板源码+可执行文件
    10. HTML5 的离线储存怎么使用, 它的工作原理是什么?
    2019 Java面试题
    map和set
    【推荐收藏】这8个常用缺失值填充技巧一定要掌握
    使用MySQL, JSON 这张牌你一定要善用
    12【组合设计模式】
    CodeQL的自动化代码审计之路(上篇)
    含文档+PPT+源码等]精品基于Uniapp+SSM实现的酒品移动电商平台app[包运行成功]计算机毕业设计Android项目源码
  • 原文地址:https://blog.csdn.net/qq_63739337/article/details/126398037
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号