Codeforces Problem 709A Juicer(implementation)
来源:互联网 发布:松井玲奈毕业 知乎 编辑:程序博客网 时间:2024/06/14 04:16
此文章可以使用目录功能哟↑(点击上方[+])
比赛链接→AIM Tech Round 3 (Div. 2)
Codeforces Problem 709A Juicer
Accept: 0 Submit: 0
Time Limit: 1 second Memory Limit : 256 megabytes
Problem Description
Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
Input
The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Output
Print one integer — the number of times Kolya will have to empty the waste section.
Sample Input
5 6
1 5 10
7
3 10 10
5 7 7
1 1 1
1
Sample Output
0
1
0
Hint
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
Problem Idea
解题思路:
【题意】
有n个大小不同的橘子,按顺序放进榨汁机中榨汁
但若某个橘子的大小超过b,则该橘子丢掉
另外,当榨汁机中的橘子总大小超过d时,会将榨汁机清空
问总共将榨汁机清空几次
【类型】
implementation
【分析】
此题思路很简单,照着题意每个橘子判断一遍就可以了
凡是大小超过b的就不考虑,用变量sum记录当前榨汁机内橘子总大小
当sum超过d,清空次数ans加1,并把sum清空
【时间复杂度&&优化】
O(n)
题目链接→Codeforces Problem 709A Juicer
Source Code
/*Sherlock and Watson and Adler*/#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<bitset>#include<cmath>#include<complex>#include<string>#include<algorithm>#include<iostream>#define eps 1e-9#define LL long long#define PI acos(-1.0)#define bitnum(a) __builtin_popcount(a)using namespace std;const int N = 2;const int M = 100005;const int inf = 1000000007;const int mod = 1000000007;int main(){ int n,b,d,a,i,sum=0,ans=0; scanf("%d%d%d",&n,&b,&d); for(i=0;i<n;i++) { scanf("%d",&a); if(a>b) continue; sum+=a; if(sum>d) sum=0,ans++; } printf("%d\n",ans); return 0;}菜鸟成长记
- Codeforces Problem 709A Juicer(implementation)
- codeforces 709A - Juicer
- CodeForces-709A. Juicer
- CodeForces 709A Juicer
- CodeForces - 709A Juicer
- Codeforces Problem 710A King Moves(implementation)
- Codeforces Problem 708A Letters Cyclic Shift(implementation)
- Codeforces Problem 711A Bus to Udayland(brute force+implementation)
- [codeforces] Juicer
- A. Juicer
- Codeforces 672A(implementation)
- Problem - 152A - Codeforces
- codeforces problem/244/A
- codeforces problem/415/A
- codeforces. problem/408/A
- Codeforces Problem 333A
- Codeforces Problem 332A
- Codeforces Problem 708B Recover the String(implementation&math)
- 【BZOJ4008】亚瑟王,概率DP
- 构造方法、析构方法的定义
- mysql_fetch_row()和mysql_fetch_array()之间有什么区别?
- Java 反射
- JQuery处理json与ajax返回JSON实例代码
- Codeforces Problem 709A Juicer(implementation)
- Amap location for React Native 高德定位
- 欢迎使用CSDN-markdown编辑器
- 关于莫名其妙的问题
- 正则匹配---C语言实现
- 常见的web安全攻击手段及解决办法
- for循环查询天数
- 勾股定理一日一证连载82
- iOS开发76-使用Xcode查看实时日志