CodeFroces 解题报告
1.题目描述
A. Juicer
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, …, a**n. 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, …, a**n (1 ≤ a**i ≤ 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.
Examples
input
Copy
2 7 10
5 6
output
Copy
1
input
Copy
1 5 10
7
output
Copy
0
input
Copy
3 10 10
5 7 7
output
Copy
1
input
Copy
1 1 1
1
output
Copy
0
Note
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.
2. 解题思路
这道题的整体思路不难,就是需要逐个获取橘子值:判断是否满足条件(<=b)满足就填入,否则丢弃,当容量超过(>d)的时候,需要清空一次,求最后清空的总次数。
这里写的时候分析题目没有分析到位,按题目的意思应该是满一次就清空,初次写题目的时候误解为求总和然后再清空。
3. 代码
1.错误代码(WA: in test 5)
// Problem: A. Juicer
// Contest: Codeforces - AIM Tech Round 3 (Div. 2)
// URL: https://codeforces.com/contest/709/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,b,d;
cin>>n>>b>>d;
vector<int>a;
while(n--){
int t;
cin>>t;
a.push_back(t);
}
int cnt=0,sum=0;
for(int i=0;i<a.size();i++){
if(a[i]<=b)sum+=a[i];
}
if(sum==d)cout<<0<<endl;
else cout<<sum/d<<endl;
return 0;
}
没有完全理解题目的意思(题目要求,当满了就进行清零),初次写题的时候错把这个意思理解成为求能放入的总和然后/容量d得到次数(忽视了,满一次就清零的说明)
AC代码
// Problem: A. Juicer
// Contest: Codeforces - AIM Tech Round 3 (Div. 2)
// URL: https://codeforces.com/contest/709/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,b,d;
cin>>n>>b>>d;
int sum=0,c=0;
while(n--){
int t;
cin>>t;
if(t<=b){
sum+=t;
}
if(sum>d){
sum=0;
c++;
}
}
cout<<c<<endl;
return 0;
}
AC代码因为if(t<=b)写成了if(t<=d)又错了好几次,只能说,下次一定要谨慎一点。