Baidu star 1001 Energy ConversionTime

Source: Internet
Author: User

Energy ConversionTime

Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission (s): 6795 Accepted Submission (s): 1642

Problem Description

When the magician was still encountering difficulties-now, baixiaodu is in front of an ancient stone door. There is an ancient magic text on the stone door, reading this magic text requires a lot of energy and a lot of mental power. After a long time, baixiao finally understood the meaning of the magic text: There is a stone tray in the stone door, the magician needs to rotate the stone tray X degrees through magic, so that the above lettering corresponds to the sky, to open the stone door. However, rotating a stone disk requires N points of energy. to interpret the ciphertext, only M points are available for the hundred degrees of energy! It is impossible to destroy the stone door, because it will require more energy. However, fortunately, being a magician's hundred degrees can consume V points of energy, turning your energy into K times of the remaining energy (you will never understand the magician's world, no one knows how he does it ). For example, now there is a point of energy in the hundred degrees, then he can make his energy into (A-V) * K points (energy at any time can not be thought negative, that is: if A is less than V, the conversion cannot be executed ). However, in the process of interpreting the ciphertext, his IQ was advanced to a hundred degrees, so he does not know whether he can rotate the stone disk and open the stone door. Can you help him?

Input 

The first line of the input data is an integer T, indicating that it contains the T group test sample. The next is the T row of data, each line has four natural numbers N, M, V, K (for the meaning of the characters, see the topic description); data range: T <= 100 N, M, V, K <= 10 ^ 8

Output

For each group of data, please output at least a few energy conversions to have enough energy points to open the door; if not, please directly output-1.

Sample Input

4

10 3 1 2

10 2 1 2

10 9 7 3

10 10 10000 0

Sample Output

3

-1

-1

0


#include
 
  #include
  
   #include#include
   
    #include
    
     #include
     
      #define INF 0x3f3f3f3f#define maxn 100001#define LL __int64using namespace std;int main(){    int t,num,ok;    scanf("%d",&t);    LL n,m,v,k,test;    while(t--)    {        ok=1;        num=0;        scanf("%I64d%I64d%I64d%I64d",&n,&m,&v,&k);        while(m
      
       



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.