For problem 10300, Ecological Premium, for each farmer case, one is given three parameters: land area (land_area), number of animals (num_animals), and degree of environmental friendliness (degree_friendliness). The problem describes that the premium due to the farmer is calculated as Equation 1.
[Equation 1]
premium = (land_area / num_animals) * degree_friendliness * num_animals
But notice from Equation 1 that num_animals can be cancelled out to simplify the formula to Equation 2.
[Equation 2]
premium = land_area * degree_friendliness
In this case, the num_animals parameter is not needed and is used to confused the solver.
So, for a given test case, we calculate the premium for each farmer. Then we sum them up to obtain the burden due by the government.
Showing posts with label Ecological Premium. Show all posts
Showing posts with label Ecological Premium. Show all posts
Friday, January 16, 2009
UVa problem 10300: Sample code
001 #include "stdio.h"
002
003 int main() {
004 char line[100]
005 ;
006
007 int num_cases
008 , num_farmers
009 , i
010 , j
011 , area
012 , num_animals
013 , factor
014 , burden
015 ;
016
017 fgets(line, 100, stdin);
018 sscanf(line, "%d", &num_cases);
019
020 for (i = 0; i < num_cases; i += 1) {
021 fgets(line, 100, stdin);
022 sscanf(line, "%d", &num_farmers);
023
024 for (j = 0, burden = 0; j < num_farmers; j += 1) {
025 fgets(line, 100, stdin);
026 sscanf(line, "%d %d %d", &area, &num_animals, &factor);
027
028 burden += area * factor;
029 }
030
031 printf("%d\n", burden);
032 }
033
034 return 0;
035 }
Subscribe to:
Posts (Atom)