本文分享的必刷题目是从蓝桥云课、洛谷、AcWing等知名刷题平台精心挑选而来,并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构,旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。
欢迎大家订阅我的专栏:算法题解:C++与Python实现!
附上汇总贴:算法竞赛备考冲刺必刷题(C++) | 汇总
【题目来源】
AtCoder:A - Preparations Before Departure
【题目描述】
Takahashi is preparing so that he won’t be late for a meeting with his friend. Takahashi needs to finish several preparation tasks before leaving.
高桥正在做准备,以免与朋友见面时迟到。高桥需要在出发前完成几项准备工作。
To make it to the meeting on time, he must leave his house byT TTo’clock0 00minutes at the latest.
为了准时赴约,他必须在T TT点0 00分之前离开家。
Takahashi hasN NNpreparation tasks, and thei ii-th task takesA i A_iAiminutes to complete. Takahashi starts preparing atS SSo’clock0 00minutes on the same day, and performs each of theN NNtasks exactly once, consecutively without any breaks. The total time for all tasks isA 1 + A 2 + ⋯ + A N A_1 + A_2 + \cdots + A_NA1+A2+⋯+ANminutes.
高桥有N NN项准备工作,第i ii项任务需要A i A_iAi分钟完成。高桥在同一天S SS点0 00分开始准备,并按顺序连续执行这N NN项任务各一次,中间不休息。所有任务的总时长为A 1 + A 2 + ⋯ + A N A_1 + A_2 + ⋯ + A_NA1+A2+⋯+AN分钟。
If he finishes all preparations at or beforeT TTo’clock0 00minutes, Takahashi can leave in time for the meeting.
如果他在T TT点0 00分或之前完成所有准备工作,高桥就能及时离开去赴约。
Determine whether Takahashi can finish all preparations and leave byT TTo’clock0 00minutes.
判断高桥是否能在T TT点0 00分之前完成所有准备工作并离开。
【输入】
N NNS SST TT
A 1 A_1A1A 2 A_2A2… \ldots…A N A_NAN
- The first line contains three space-separated integers:N NN, the number of preparation tasks;S SS, the hour at which preparation starts; andT TT, the hour of the departure deadline.
- The second line contains space-separated integersA 1 , A 2 , … , A N A_1, A_2, \ldots, A_NA1,A2,…,AN, representing the time (in minutes) each task takes.
【输出】
If Takahashi can finish all preparations and leave byT TTo’clock0 00minutes, printYes; otherwise, printNo.
【输入样例】
3 9 10 15 20 10【输出样例】
Yes【解题思路】
【算法标签】
#模拟#
【代码详解】
#include<bits/stdc++.h>usingnamespacestd;intn,s,t;// n: 题目数量,s: 考试开始时间(分钟),t: 考试结束时间(分钟)intsum;// 总耗时intmain(){cin>>n>>s>>t;// 读入题目数量和考试起止时间s=s*60;// 将开始时间转换为秒t=t*60;// 将结束时间转换为秒for(inti=1;i<=n;i++){intx;cin>>x;// 读入每道题需要的时间(秒)sum+=x;// 累加总耗时}// 判断从开始时间s开始,完成所有题目后是否超过结束时间tif(s+sum>t){cout<<"No"<<endl;// 无法完成}else{cout<<"Yes"<<endl;// 可以完成}return0;}【运行结果】
3 9 10 15 20 10 Yes