10554 - Calories from Fat

All about problems in Volume 105. 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
dust_cover
New poster
Posts: 23
Joined: Tue Sep 12, 2006 9:46 pm

10554 - Calories from Fat

Post by dust_cover »

Can someone tell me how to calculate the PERCENTAGE CALORIES to calories. I cant get it through!

Plz Help! Thanx in Advance
i wanna give it a try....
sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Post by sakhassan »

- Post in an existing thread if possible;
- If there isn't one, create one with the problem number and title in the subject line;
- If you need to publish code, use code tags.
outsbook
New poster
Posts: 26
Joined: Fri Oct 28, 2011 2:42 am

10554 - Calories from Fat

Post by outsbook »

For grams to Calories, you are given a rules that:

1g fat = 9 Calories,
1g protein = 4 Calories,
1g sugar = 4 Calories,
1g starch = 4 Calories,
1g alcohol = 7 Calories

I think now the problem is very easy. :D

Remember that use double for all calculation
"Learning to love yourself is the greatest love of all" - Michael Masser and Linda Creed
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10554 - Calories from Fat

Post by uDebug »

I think now the problem is very easy.
Honestly, I struggled with this problem. This is one of those questions that's verbose and so it's harder to distil out the essence.

That being said, here's some input / output I found useful during testing / debugging.

Input:

Code: Select all

3g 10g 10% 0g 0g
32% 300C 2% 0g 30g
4g 4% 900C 6% 5%
6g 5g 70g 100g 6g
-
13g 8% 10% 2g 3g
67% 30C 2% 5g 30g
54g 4% 8% 6g 5%
68g 5g 9g 1g 2g
-
32% 300C 2% 0g 30g
4g 4% 900C 6% 5%
-
-
AC Output:

Code: Select all

13%
77%
15%
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10554 - Calories from Fat

Post by uDebug »

If you need help with this problem, check out this thread.

http://online-judge.uva.es/board/viewto ... 27&t=70265
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Re: 10554 - Calories from Fat

Post by Dominik Michniewski »

Could anyone post more test cases ?
I am almost sure that my algorithm is correct, but I am getting WA :(

Idea of algorithm is:
1. convert grams to calories;
2. convert percents to calories;
3. when the whole dataset is read, sum up every type of ingridients and count percentage for fat

I have tested my program against random input (5 000 products with 1-20 lines per product) - the results are the same as the one given from uDebug page ...

My code is below (I do not like to post code, but I am too frustrated with this problem):

Code: Select all

CODE REMOVED
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Re: 10554 - Calories from Fat

Post by Dominik Michniewski »

I have found problem - it was related to rounding ...

Example case:

Code: Select all

20g 16% 36C 47% 80C
-
-
Result is exactly 22.5% - rounding to nearest integer can be painful :)
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Post Reply

Return to “Volume 105 (10500-10599)”