11046 - Numbers and operations

All about problems in Volume 110. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Emilio
Experienced poster
Posts: 163
Joined: Sun Oct 17, 2004 8:31 pm
Location: Murcia, Spain

11046 - Numbers and operations

Post by Emilio »

Hi,

one question. Is it not better this solution for the third case of the input/output examples?

25 x 11 = 275
275 + 13 = 288
288 - 17 = 271
271 x 7 = 1897 <-

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

For operations with the same operator, it will be preferred the one involving the number whose position is lower in the order in which they were given in the input (it appears first).
Since 2 appears before 11, "25 x 2 = 50" is preferred over "25 x 11 = 275".

Emilio
Experienced poster
Posts: 163
Joined: Sun Oct 17, 2004 8:31 pm
Location: Murcia, Spain

Post by Emilio »

Thanks firstly!
Ah! OK!
I put in preference the operators before the operands because they are with a greater priority.
Then the first solution of minimum number of operations can be the solution if you do the things in a good manner.
But another question, how do you handle cases where multiply operations can give very large numbers?

sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:

Post by sclo »

you know that the input numbers are less than 200, there are at most 7 input numbers, and the final answer must be less than 2000, so what's the largest possible intemediate result? Can it fit inside int?

Emilio
Experienced poster
Posts: 163
Joined: Sun Oct 17, 2004 8:31 pm
Location: Murcia, Spain

Post by Emilio »

Really my question was stupid!
But I don't know where my code fails. Could anyone take a look?

Code: Select all

Code removed after AC
Thanks in advance!
Last edited by Emilio on Mon Jun 12, 2006 6:32 pm, edited 1 time in total.

gines
New poster
Posts: 1
Joined: Mon Jun 12, 2006 4:22 pm

Post by gines »

Hi Emilio,

I think you are having a problem with the precedence of the operations. For example, in the following cases:

800 6 71 9 101 73 7 139
732 7 91 7 57 17 87 92 125

Your program gives:

71 + 9 = 80
80 x 7 = 560
560 + 101 = 661
661 + 139 = 800 <-
91 x 7 = 637
637 + 57 = 694
694 - 87 = 607
607 + 125 = 732 <-

And it should be:

71 + 9 = 80
139 + 101 = 240
80 x 7 = 560
560 + 240 = 800 <-
92 + 91 = 183
125 - 57 = 68
183 x 68 = 12444
12444 / 17 = 732 <-

I hope it helps!
Good luck for SWERC'06 :)
http://dis.um.es/contest/acm/regional_murciana.htm

Emilio
Experienced poster
Posts: 163
Joined: Sun Oct 17, 2004 8:31 pm
Location: Murcia, Spain

Post by Emilio »

Hi gines,

you was right. I have got AC with a small change in my code.

Thanks to all for all :)

shanto86
Experienced poster
Posts: 160
Joined: Wed Jul 30, 2003 8:10 pm

Post by shanto86 »

please help some one, i am getting WA, (my time is also high, can any one give some tips for making the time low?)

Code: Select all

AC
Last edited by shanto86 on Fri Aug 25, 2006 5:17 am, edited 1 time in total.
Self judging is the best judging!

shanto86
Experienced poster
Posts: 160
Joined: Wed Jul 30, 2003 8:10 pm

Post by shanto86 »

Input:
11 4 5 10 1 6

Output:
10 + 1 = 11 <-
Self judging is the best judging!

Post Reply

Return to “Volume 110 (11000-11099)”