当前位置:网站首页>2022 RoboCom 世界机器人开发者大赛-本科组(省赛)---第一题 不要浪费金币 (已完结)
2022 RoboCom 世界机器人开发者大赛-本科组(省赛)---第一题 不要浪费金币 (已完结)
2022-07-24 15:13:00 【trudbot】
题目
RC-u1 不要浪费金币
哲哲最近在玩一个游戏,击杀怪物能获得金币 —— 这里记击杀第 i 个怪物获得的金币数量为 Pi。
然而这个游戏允许拥有的金币数量是有上限的,当超过时,超过上限的部分就会被系统光明正大地吃掉,哲哲就拿不到了。
为了不浪费金币,哲哲决定,当下一个要击杀的怪物可获得的金币会导致自己拥有的金币数量超过上限时,就去消费一次,把自己已有的金币全部用完。
现在给定哲哲将要击杀的一系列怪物对应的金币数量,请你计算一下哲哲去消费了几次。
输入格式:
输入第一行是两个整数 N,M (1≤N≤1e3 ,1≤M≤1e6),表示击杀的怪物数量以及系统允许拥有金币数量的上限。
接下来一行是由空格隔开的 N 个数 Pi(i=1,⋯,N),依次表示击杀第 i 个怪物能获得的金币数量。
假设哲哲是按输入顺序击杀怪物的,并且每个 Pi都是 不超过 1e6的非负整数。
输出格式:
在一行中输出哲哲去消费的次数。
** 输入样例:**
10 10
1 2 3 4 1 2 3 5 11 1
输出样例:
4
样例解释:
消费时间点为:第四个怪物击杀后、第七个怪物击杀后、第八个怪物击杀后、第九个怪物击杀后。
题解
题目很简单, 用循环进行模拟即可.我们在对数组进行求和的过程中, 每当sum加上当前元素的值要超过m, 我们就把sum置0, 同时计数器加1
AC代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int arr[N];
int main()
{
int n, m;
cin >> n >> m;
for(int i=1; i<=n; i++) cin >> arr[i];
int res = 0;
int sum = 0;
for(int i=1; i<=n; i++)
{
if(sum + arr[i] > m)
{
res++;
sum = 0;
}
sum += arr[i];
}
cout << res << endl;
return 0;
}

如上代码可AC, 有任何问题欢迎讨论交流
边栏推荐
- XOR procedure
- pytorch with torch.no_ grad
- Similarities and differences between nor flash and NAND flash
- Getting started with mongodb
- Attributeerror: module 'distutils' has no attribute' version error resolution
- Under multi data source configuration, solve org.apache.ibatis.binding Bindingexception: invalid bound statement (not found) problem
- Conflict resolution of onblur and onchange
- Decrypt "sea Lotus" organization (domain control detection and defense)
- Jmeter-调用上传文件或图片接口
- LeetCode高频题56. 合并区间,将重叠的区间合并为一个区间,包含所有区间
猜你喜欢
![[300 opencv routines] 238. Harris corner detection in opencv](/img/d7/abdada7cd97060c55861b1bc2a2e13.png)
[300 opencv routines] 238. Harris corner detection in opencv

华为无线设备配置WPA2-802.1X-AES安全策略

Android section 13 detailed explanation of 03sqlite database

24.原生磁盘的使用

Android SQLite database practice
![[USENIX atc'22] an efficient distributed training framework whale that supports the super large-scale model of heterogeneous GPU clusters](/img/dc/be4dc55cdf3085a7b9e58ed6d6a16e.png)
[USENIX atc'22] an efficient distributed training framework whale that supports the super large-scale model of heterogeneous GPU clusters

Operation of MySQL Library

MySQL build master-slave synchronization - build with docker

Discussion and legitimacy of the order of entering and leaving the stack

Jmeter-调用上传文件或图片接口
随机推荐
云开发单机版图片九宫格流量主源码
Huffman tree (optimal binary tree)
图的存储和遍历
Huawei wireless device configuration wpa2-802.1x-aes security policy
Detailed explanation of address bus, data bus and control bus
[tkinter beautification] window out of system style (common to three systems)
Summary of Baimian machine learning
Outlook tutorial, how to set rules in outlook?
25. From disk to file
华为相机能力
Under multi data source configuration, solve org.apache.ibatis.binding Bindingexception: invalid bound statement (not found) problem
Google Earth engine - use MODIS data to export the fire area of monthly data
DS diagram - the shortest path of the diagram (excluding the code framework)
Caffe framework and production data source for deep learning
Fraud detection cases and Titanic rescued cases
Spark Learning Notes (III) -- basic knowledge of spark core
(09) flask is OK if it has hands - cookies and sessions
JS native - array sorting to find out the characters with the largest number of strings
【MATLAB】MATLAB画图系列二 1.元胞与数组转化 2.属性元胞 3.删除nan值 4.合并多fig为同一fig 5.合并多fig至同一axes
pip换源