当前位置: 首页 > news >正文

PAT甲级1008 Elevator

题目地址:1008 Elevator - PAT (Advanced Level) Practice (pintia.cn)


介绍

The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.

For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.

Input Specification:

Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.

Output Specification:


For each test case, print the total time on a single line. 

代码

	#include<bits/stdc++.h>using namespace std;#define ll long long  #define ull unsigned long longvoid solve() {ll n;cin>>n;int now_floor=0;int sum_time=n*5;vector<int> ssr;int num1;for(int i=0;i<n;i++){cin>>num1;if(num1>now_floor)sum_time+=((num1-now_floor)*6);else sum_time+=(abs(num1-now_floor)*4);now_floor=num1;}cout<<sum_time;}signed main() {ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);ll t = 1; // std::cin >> t;while (t--) {solve();}}

http://www.lryc.cn/news/467874.html

相关文章:

  • 数据导入导出
  • git的安装以及入门使用
  • 【acwing】算法基础课-搜索与图论
  • 502 错误码通常出现在什么场景?
  • 面试经典算法题69-两数之和
  • 在 Spring 框架中,循环依赖是指两个或多个 Bean 之间相互依赖
  • 一文带你入门Flink CDC
  • 修复jenkins SSH 免密登录发布服务器
  • 049_python基于Python的热门微博数据可视化分析
  • 中国信通院联合中国电促会开展电力行业企业开源典型实践案例征集
  • LOAM 20.04 ros1安装
  • Pyqt5设计打开电脑摄像头+可选择哪个摄像头(如有多个)
  • mysqldump 批量导出数据库表
  • 前端工程师面试题整理
  • Linux 权限的理解
  • 『完整代码』按钮开关UI界面
  • 梦结束的地方 -- 爬楼梯
  • 身份证识别JAVA+OPENCV+OCR
  • 独立开发者如何利用AI实现高收入
  • Go第三方框架--gorm框架(一)
  • ONLYOFFICE文档8.2:开启无缝PDF协作
  • 内网python smtplib用ssh隧道通过跳板机发邮件
  • 基于C#开发游戏辅助工具的Windows底层相关方法详解
  • SSRF+Redis进行内网渗透
  • 栈与队列-Java【力扣】【算法学习day.7】
  • 最新版本!IntelliJ IDEA 2024.2.4 (Ultimate Edition) 的新特性
  • 从头学PHP之运算符
  • 使用 Git LFS(大文件存储)
  • js 将一维数组转换成树形结构的方法
  • HarmonyOS NEXT开发实战:实现高效下拉刷新与上拉加载组件(二)刷新核心逻辑与空页面集成