You have a nuts and lots of boxes. The boxes have a wonderful feature: if you put x (x ≥ 0) divisors (the spacial bars that can divide a box) to it, you get a box, divided into x + 1 sections.
You are minimalist. Therefore, on the one hand, you are against dividing some box into more than k sections. On the other hand, you are against putting more than v nuts into some section of the box. What is the minimum number of boxes you have to use if you want to put all the nuts in boxes, and you have b divisors?
Please note that you need to minimize the number of used boxes, not sections. You do not have to minimize the number of used divisors.
The first line contains four space-separated integers k, a, b, v (2 ≤ k ≤ 1000; 1 ≤ a, b, v ≤ 1000) — the maximum number of sections in the box, the number of nuts, the number of divisors and the capacity of each section of the box.
Print a single integer — the answer to the problem.
3 10 3 3
2
3 10 1 3
3
100 100 1 1000
1
In the first sample you can act like this:
- Put two divisors to the first box. Now the first box has three sections and we can put three nuts into each section. Overall, the first box will have nine nuts.
- Do not put any divisors into the second box. Thus, the second box has one section for the last nut.
In the end we've put all the ten nuts into boxes.
The second sample is different as we have exactly one divisor and we put it to the first box. The next two boxes will have one section each.
题意:求将核桃全部装进箱子所用的最少箱子数...
思路:一开始没有想全情况,就开始敲代码,越敲越不对,后来代码重新删了再写...用了1:19才把它AC了TT..
思路:使用循环,每一次都使用最大的d,还要判断d和f的关系..直到a小于等于0为止..
Code:
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int k,a,b,v,n,ans=0,t;
scanf("%d%d%d%d",&k,&a,&b,&v);
if(v>=a)printf("1\n");
else
{
while(a>0)
{
t=b+1;
for(int i=1;i<=b;i++)
{
if(((i+1)*v)>=a)
{
t=i+1;
break;
}
}
if(t>k)t=k;
a=a-(t*v);
ans++;
if(a<=v&&a>0)
{
a=a-v;
ans++;
}
b=b-t+1;
}
printf("%d\n",ans);
}
return 0;
}
...后来和大神讨论..发现自己这种做法实在笨,,,
直接把此题当成数学问题...先求出装核桃所需的格子数..再进行计算..容易得多了..
CODE:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
// freopen("in.in","r",stdin);
int k,a,b,v;
scanf("%d%d%d%d",&k,&a,&b,&v);
int num=a/v+ (a%v==0?0:1);
int ans=0;
while((b>=k-1)&&num>0)
{
b=b-k+1;
num-=k;
ans++;
}
if(num>0)
{
num-=(b+1);
ans++;
}
if(num>0) ans+=num;
printf("%d\n",ans);
return 0;
}
思路:比赛时忽略了最少步...直接就把第一棵树作为基准去修剪后面的树...加上去便WA了...找出问题时已经time over了..
把所有的数都遍历一遍...得到修剪的最少步数..记得将基准树记录下来...
CODE:
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int INF=0xfffffff;
int main()
{
//freopen("B.txt","r",stdin);
int n,k,cur;
int a[1005];
while(~scanf("%d%d",&n,&k))
{
int mann=INF,st=1,cur;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++)
{
cur=0;
int t=a[i]-k*(i-1);
if(t<=0) continue;
for(int j=1;j<=n;j++)
{
if(a[j]!=t) cur++;
t+=k;
}
if(mann>cur)
{mann=cur;
st=i;}
}
printf("%d\n",mann);
int t=a[st]-k*(st-1);
for(int i=1;i<=n;i++)
{
if(t-a[i]>0)
{
printf("+ %d %d\n",i,t-a[i]);
}
else if(t-a[i]<0)
{
printf("- %d %d\n",i,a[i]-t);
}
t+=k;
}
}
return 0;
}
...现今的水平只到做两道题的份上了...继续加油!!!