Home c++ Task with ACMP with an incorrect solution C++

Task with ACMP with an incorrect solution C++




Condition Tasks :

In some state, N firms competing with each other. Each company has some profit per year equal to V [I] American rubles. The king has a favorite firms, and there are unloved. Accordingly, the tax for all firms is different and is appointed by the king individually. Tax on the i-uh company is p [i] percent.

Statistics gatherers decided to calculate, from which company in the state treasury there is the greatest income (all taxes go to the treasury). Unfortunately, they did not teach either mathematics or informatics in childhood (so learn, children!), And their task is sharply complicated.

In the input file input.txt, the number N is the number of firms (0 & lt; n ≤ 100). Next comes N as many non-negative numbers not exceeding 154 – incomes of firms, and then another n integers from 0 to 100 – Taxes of firms in percent.

In the output file Output.txt, output one number – the number of the company from which the state receives the greatest tax. If there are several such firms, output the company with the smallest number.

What is essentially done? Remove the maximum element index, which is A * (B / 100) .

The first thing you can do: let’s say we built a profit ascending.

a_1 * (b_1 / 100) & lt; a_2 * (b_2 / 100) & lt; ... & lt; a_n * (b_n / 100) | * 100 (Doming on 100 this inequality)
a_1 * b_1 & lt; a_2 * b_2 & lt; a_3 * b_3 & lt; ... & lt; A_N * B_N.

Thus, we need to find the index n such that a_n * b_n = max (a_1 * b_1, a_2 * b_2, ..., a_n * b_n) , and even even via floating Point do not have to use.

My decision:

# include & lt; bits / stdC++. H & GT;
Using Namespace STD;
  int t;
  CIN & GT; & GT; t;
  INT MXCNT = -1; // Variable for recording the maximum value A_K * B_K
  int id = -1; // Record index for this value.
  for (int i = 0; i & lt; t; i ++)
    int a, b;
    CIN & GT; & GT; a & gt; & gt; b;
    if (A * B & GT; MXCNT)
      MXCNT = A * B;
      id = i + 1;
  COUT & LT; & LT; ID;

But in some of the initial tests, my solution gives an incorrect answer. What could be the problem? My idea in my own wrong? Or does the program stumbles on some particular cases?

Answer 1, Authority 100%

Because they are not in pairs of “income percentage”, but first a series of income, then a series of percent – reread the condition …

So a complete solution for C++ for ACMP (they like shorter :)) –

# include & lt; iostream & gt;
int v [100], n, m = -1, i, j, d;
#Define X STD :: CIN & GT; & GT;
Main ()
  x n;
  for (; i & lt; n; x v [i ++]);
  for (x n;)
    if ((n * = v [j ++]) & gt; m) m = n, d = j;
  STD :: COUT & LT; & LT; d;

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions