当前位置:网站首页>2022 robocom world robot developer competition - undergraduate group (provincial competition) -- question 1: don't waste gold (finished)
2022 robocom world robot developer competition - undergraduate group (provincial competition) -- question 1: don't waste gold (finished)
2022-07-24 15:14:00 【trudbot】
subject
RC-u1 Don't waste gold
Zhe Zhe is playing a game recently , You can get gold coins by killing monsters —— Here, remember to kill the first i The number of gold coins obtained by monsters is Pi.
However, there is a limit to the number of gold coins allowed in this game , When over , The part exceeding the upper limit will be eaten openly by the system , Zhe zhe can't get it .
In order not to waste gold , Zhe zhe decides , The next monster to be killed can get gold coins, which will cause the number of gold coins he has to exceed the limit , Just spend once , Use up all the gold coins you have .
Now, given the number of gold coins corresponding to a series of monsters that zhe zhe will kill , Please calculate how many times zhe zhe spent .
Input format :
The first line of input is two integers N,M (1≤N≤1e3 ,1≤M≤1e6), Indicates the number of monsters killed and the maximum number of gold coins allowed by the system .
The next line is separated by spaces N Number Pi(i=1,⋯,N), It means to kill the first i The number of gold coins a monster can get .
Suppose zhe zhe kills monsters in the order of input , And each Pi All are No more than 1e6 Non-negative integer .
Output format :
Output the number of times philosophers spend in one line .
** sample input :**
10 10
1 2 3 4 1 2 3 5 11 1
sample output :
4
Sample explanation :
The consumption time point is : After the fourth monster is killed 、 After the seventh monster is killed 、 After the eighth monster is killed 、 After the ninth monster is killed .
Answer key
The subject is very simple , Simulate with a loop . We are in the process of summing the array , whenever sum Add the value of the current element to exceed m, We will take sum Set up 0, At the same time, the counter is incremented 1
AC Code
#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;
}

The above code can AC, Welcome to discuss and exchange any questions
边栏推荐
- SQL的SELF JOIN用法
- Google Earth engine - use MODIS data to export the fire area of monthly data
- Which brokerage has the lowest commission? I want to open an account. Is it safe to open an account on my mobile phone
- LeetCode·每日一题·1184.公交站间的距离·模拟
- C language large and small end mode judgment function
- Discussion on the basic use and address of pointer in array object
- Under multi data source configuration, solve org.apache.ibatis.binding Bindingexception: invalid bound statement (not found) problem
- zabbix管理员忘记登录密码
- Attributeerror: module 'distutils' has no attribute' version error resolution
- DS graph - minimum spanning tree
猜你喜欢

(09) flask is OK if it has hands - cookies and sessions
![[300 opencv routines] 238. Harris corner detection in opencv](/img/d7/abdada7cd97060c55861b1bc2a2e13.png)
[300 opencv routines] 238. Harris corner detection in opencv

Use of keywords const, volatile and pointer; Assembly language and view of register status

Cloud development standalone image Jiugongge traffic main source code

【OpenCV 例程300篇】238. OpenCV 中的 Harris 角点检测
![Property datasource is required exception handling [idea]](/img/f3/50d36ed9445695c02e2bd622109d66.png)
Property datasource is required exception handling [idea]

27. Directory and file system

MySQL build master-slave synchronization - build with docker

打假Yolov7的精度,不是所有的论文都是真实可信

Android section 13 detailed explanation of 03sqlite database
随机推荐
spark:获取日志中每个时间段的访问量(入门级-简单实现)
Route planning method for UAV in unknown environment based on improved SAS algorithm
How do novices buy stocks for the first time? Which securities company is the best and safest to open an account
Performance test - Test Execution
Data analysis and mining 2
Kali concise language transformation method (illustration)
Sword finger offer II 001. integer division
Property datasource is required exception handling [idea]
VSCode如何调试Nodejs
Simple encapsulation of wechat applet wx.request
MongoDB入门学习
onBlur和onChange冲突解决方法
【机器学习基础】——另一个视角解释SVM
[USENIX atc'22] an efficient distributed training framework whale that supports the super large-scale model of heterogeneous GPU clusters
Spark: get the access volume of each time period in the log (entry level - simple implementation)
Activate the newly installed Anaconda in the server
文件操作详解
Similarities and differences between nor flash and NAND flash
Tensorflow framework of deep learning realizes vgg/rnn network / verification code generation and recognition / text classification
多数据源配置下,解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题