Luo Gu CF402A Nuts solution to a problem

This konjac solution to a problem again made it!

This title is a purple question?

Well, malicious score may starfish?

Back to the topic

This question is obviously greedy ah;

There are a nut a, b baffles, x baffles, v up into intervals.

So our strategy is greedy:

If the total is less than using baffles x, k and less than the current number of boxes.

So, in this case would continue to increase until it becomes greater than, the water is very right.

Directly look at the code (A Detailed:

#include<bits/stdc++.h>
using namespace std;

int a, b, k, v, sum, ans;
//a, b, k, v如题,sum是当前箱子的区间数,ans 是箱子的个数 
int main()
{
scanf("%d%d%d%d", &k, &a, &b, &v);//输入k, a, b, v; 
while(true)//有点皮,不过就是这么写的 
{
if(a <= 0)//如果坚果装够了,那就跳出。 
break;
sum = 1;//最开始的每个箱子中都有一个区间 
while(b > 0)//如果还有隔板 
if(sum < k)//且这个箱子中区间的个数小于k 
{
++ sum;//区间个数加加 
-- b;//隔板数目减减 
}
else
break;//如果没隔板了就退出 
a -= sum * v;//坚果的个数要减去这个箱子中的区间的个数 乘上 最大坚果量的个数
//莫非你一个区间内可以装v个,你却只装1个,还是v - 1个? 
++ ans;//统计箱子个数; 
}
printf("%d", ans);//输出啦 
return 0;
}

This konjac and double Cheese Li stepped-bomb

Guess you like

Origin www.cnblogs.com/Flash-plus/p/12028329.html