2014 Baidu star question 1001

Source: Internet
Author: User

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
410 3 1 210 2 1 210 9 7 310 10 10000 0
 
Sample Output
3-1-10


The Baidu star qualifying round ended, including the questions and the code you wrote.


This is the first question. However, it seems that many people are annoyed.

In fact, it is also very simple, that is, pay attention to two points:

1. When the conversion energy is less than or equal to the original energy, the system jumps out of the cycle, indicating that the magic door cannot be opened successfully.

2. The conversion process may be larger than the integer number. You must use the long type.

# Include <stdio. h> class EnergyConversion_2 {int calconvertTimes (long n, long m, int v, int k) {int t = 0; long left = m; while (m <n) {if (m> v) m = (m-v) * k; // do not use m> = velse return-1; if (m <= left) return-1; left = m; t ++;} return t;} public: EnergyConversion_2 () {int T, N, M, V, K; scanf ("% d ", & T); while (T --) {scanf ("% d", & N, & M, & V, & K ); printf ("% d \ n", calconvertTimes (N, M, V, K ));}}};




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.