Can someone tell me how to calculate the PERCENTAGE CALORIES to calories. I cant get it through!
Plz Help! Thanx in Advance
10554 - Calories from Fat
Moderator: Board moderators
-
- New poster
- Posts: 23
- Joined: Tue Sep 12, 2006 9:46 pm
10554 - Calories from Fat
i wanna give it a try....
10554 - Calories from Fat
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](./images/smilies/icon_biggrin.gif)
Remember that use double for all calculation
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](./images/smilies/icon_biggrin.gif)
Remember that use double for all calculation
"Learning to love yourself is the greatest love of all" - Michael Masser and Linda Creed
Re: 10554 - Calories from Fat
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.I think now the problem is very easy.
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%
-
-
Code: Select all
13%
77%
15%
Re: 10554 - Calories from Fat
If you need help with this problem, check out this thread.
http://online-judge.uva.es/board/viewto ... 27&t=70265
http://online-judge.uva.es/board/viewto ... 27&t=70265
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
Re: 10554 - Calories from Fat
Could anyone post more test cases ?
I am almost sure that my algorithm is correct, but I am getting WA![:(](./images/smilies/icon_frown.gif)
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):
I am almost sure that my algorithm is correct, but I am getting WA
![:(](./images/smilies/icon_frown.gif)
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)
Born from ashes - restarting counter of problems (800+ solved problems)
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
Re: 10554 - Calories from Fat
I have found problem - it was related to rounding ...
Example case:
Result is exactly 22.5% - rounding to nearest integer can be painful ![:)](./images/smilies/icon_smile.gif)
Example case:
Code: Select all
20g 16% 36C 47% 80C
-
-
![:)](./images/smilies/icon_smile.gif)
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)
Born from ashes - restarting counter of problems (800+ solved problems)