程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces Round #236 (Div. 2)A

Codeforces Round #236 (Div. 2)A

編輯:C++入門知識

A. Nuts time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

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.

Input

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.

Output

Print a single integer — the answer to the problem.

Sample test(s) input
3 10 3 3
output
2
input
3 10 1 3
output
3
input
100 100 1 1000
output
1
#include 
#include
#include
#include
#define MAX 101
int k,a,b,v;
int main()
{
   freopen("input.txt","r",stdin);
   while(scanf("%d%d%d%d",&k,&a,&b,&v)!=EOF)
   {
       int count=0;
       if(a%v==0)count=a/v;else count=a/v+1;
       if(k==1)printf("%d\n",count);
       if(k>=count&&b>=count-1)printf("1\n");
       else
       {
           int ok=1,n=0,s=0,sum=0;
           for(int i=1;i<=b;i++)
           {
               if(ok)n++;
               ok=0;s++;
               if(i%(k-1)==0)
               {
                   ok=1;
                   sum+=k;
                   s=0;
                   if(sum==count)break;
               }
               if(sum+s+1==count)break;
           }
           if(s)sum+=s+1;
           n+=count-sum;
           printf("%d\n",n);
       }
   }
    return 0;
}



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved