当前位置:网站首页>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
边栏推荐
- 25. From disk to file
- Fraud detection cases and Titanic rescued cases
- The accuracy of yolov7 in cracking down on counterfeits, not all papers are authentic
- zabbix管理员忘记登录密码
- Huffman tree (optimal binary tree)
- Kali concise language transformation method (illustration)
- C # exit login if there is no operation
- 26.文件使用磁盘的代码实现
- 使用 Fiddler Hook 报错:502 Fiddler - Connection Failed
- Discussion on the basic use and address of pointer in array object
猜你喜欢

Outlook tutorial, how to set rules in outlook?

Rest style

Leetcode high frequency question 56. merge intervals, merge overlapping intervals into one interval, including all intervals

Deep learning 1 perceptron and implementation of simple back propagation network

VSCode如何调试Nodejs

Overview of dobesie wavelet (DB wavelet function) in wavelet transform

Sword finger offer II 001. integer division

使用 Fiddler Hook 报错:502 Fiddler - Connection Failed
![Property datasource is required exception handling [idea]](/img/f3/50d36ed9445695c02e2bd622109d66.png)
Property datasource is required exception handling [idea]

Leetcode 1288. delete the covered interval (yes, solved)
随机推荐
PrestoUserError: PrestoUserError(type=USER_ERROR, name=INVALID_FUNCTION_ARGUMENT, message=“Escape st
Kotlin类与继承
Wildfire STM32 domineering, through the firmware library to achieve water light
The vs compiled application is missing DLL
SQL的SELF JOIN用法
Data analysis and mining 2
[matlab] matlab drawing Series II 1. Cell and array conversion 2. Attribute cell 3. delete Nan value 4. Merge multiple figs into the same Fig 5. Merge multiple figs into the same axes
Similarities and differences between nor flash and NAND flash
Self join usage of SQL
Google Earth Engine——使用MODIS数据进行逐月数据的过火(火灾)面积并导出
多数据源配置下,解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
Preparation of mobile end test cases
DS graph - minimum spanning tree
Various searches (⊙▽⊙) consolidate the chapter of promotion
Date processing bean
(零九)Flask有手就行——Cookie和Session
Data analysis and mining 1
老虎口瀑布:铜梁版小壶口瀑布
Deep learning 1 perceptron and implementation of simple back propagation network
Research Summary / programming FAQs