The first question of the 201,400-degree star qualifying race

Source: Internet
Author: User
Energy Conversion Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 11867 Accepted Submission (s): 2861


Problem Description
The Magician hundred Small degree also has encountered the time of the difficulty--now, hundred degrees is in front of an ancient stone gate, the stone Gate has an ancient magic text, reads this kind of magic text to need to expend the massive energy and the massive brain power.   After a long time, hundred degrees finally read the meaning of magic words: There is a stone in Shek Mun, the magician need to through magic to circle the stone X-degree, so that the above the engraved lines and the sky, in order to open the shimen. However, the rotation of the stone plate requires an n-point energy value, and in order to decipher the ciphertext, the energy value of the hundred degrees is only m point. It is impossible to destroy a stone gate because it will require more energy. Fortunately, however, as a magician's hundred degrees can consume v-point energy, making his energy into the current of the remaining energy of the K-Fold (Wizard of the world you never understand, no one knows how he did it).   For example, now that the A-V has a point energy, then he can turn his energy into a *k point (the energy cannot be negative at any time, i.e. if A is less than V, it cannot perform the conversion). However, in the process of deciphering the ciphertext, the hundred-degree advance his IQ, so he does not know whether he can rotate the stone plate, open the shimen, you can help him.
Input
Input data The first line is an integer t, which indicates that the sample containing the T group test, followed by the T-line data, each line has 4 natural number n,m,v,k (the character meaning see the title description); Data range: t<=100 n,m,v,k <= 10^8
Output
For each set of data, please output a minimum number of energy conversion to be able to have enough energy points to open the door; if not, please output-1 directly.
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

The first question is the sign-in water question, directly on the code:
#include <stdio.h>
#include <iostream>
using namespace std;
int main ()
{
    int t;
    while (scanf ("%d", &t)!=eof)
    {while
        (t--)
        {
            long long n,m,v,k;
            int cnt=0;;
            cin>>n>>m>>v>>k;
            while (n>m)
            {
                if (m-v>0&&m< (m-v) *k)
                {
                    m= (m-v) *k;
                    cnt++;
                }
                else break;
            }
            if (n>m) puts ("-1");
            else printf ("%d\n", CNT);
        }
    }
    return 0;
}


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.