Uri 1160, beginner using visualg, repeat

Asked

Viewed 61 times

0

The problem is in https://www.urionlinejudge.com.br/judge/pt/problems/view/1160:

Mariazinha wants to solve an interesting problem. Given the population information and the growth rate of any two cities (A and B), she would like to know how many years it will take for the smaller city (always city A) to surpass city B in population. Of course she only wants to know for cities whose city growth rate A is higher than city B’s growth rate, therefore, previously already separated for you only test cases that have the highest growth rate for city A. Your task is to build a program that presents the time in years for each test case.

However, in some cases the time can be very long, and Mariazinha is not interested in knowing exactly the time for these cases. Just inform, in this situation, the message "More than 1 century.".

Entree

The first line of the entry contains a single integer T, indicating the number of test cases (1 T 3000). Each test case contains 4 numbers: two integers PA and PB (100 PA 1000000, PA < PB 1000000) indicating respectively the population of A and B, and two values G1 and G2 (0.1 G1 10.0, 0.0 G2 10.0, G2 < G1) with one digit after the decimal point each, indicating respectively the population growth of A and B (in percentage).

Attention: The population is always a whole value, so a growth of 2.5% over a population of 100 will result in 102 people, not 102.5 people, while a growth of 2.5% over a population of 1000 people will result in 1025 people. Also, do not use simple precision variables for growth rates.

Exit

Print out, for each test case, how many years will it take for city A to surpass city B in number of inhabitants. Note: if the time is more than 100 years the program must display the message: More than 1 century. In this case, I believe it is better to stop the program immediately after 100 years, otherwise you may receive as a response to the submission of this problem "Time Limit Exceeded".


I tried to solve it this way:

var
  A,B,per_A,per_B,FA_ano,FB_ano: real
inicio
// Seção de Comandos
   A <- 90000000
   B <- 200000000
   per_A <- (90000000 * 3)/100
   per_B <- (200000000 * 1.5)/100
   FA_ano <- 0
   FB_ano <- 0
   repita
         FA_ano <- A + per_A
         FB_ano <- B + per_B
   ate FA_ano = FB_ano
       escreval (FA_ano)
       escreval (FB_ano)
fimalgoritmo

But it doesn’t match the data entry of the problem, I can’t do otherwise, someone can help me?

  • You have to calculate per_A and per_B with each iteration. The growth rate is relative to the current population and not to the initial population value.

  • 1

    Did you happen to notice that FA_ano and FB_ano form straight lines that meet at the origin? And that they have different inclinations? What would be the next meeting point of these 2 lines?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.