UVA 12502 Three Families (A)

Three Families 

Three families share a garden. They usually clean the garden together at the end of each week, but last week, family C was on holiday, so family A spent 5 hours, family B spent 4 hours and had everything done. After coming back, family C is willing to pay $90 to the other two families. How much should family A get? You may assume both families were cleaning at the same speed.

$90/(5+4)*5=$50? No no no. Think hard. The correct answer is $60. When you figured out why, answer the following question: If family A and B spent x and y hours respectively, and family C paid $z, how much should family A get? It is guaranteed that both families should get non-negative integer dollars.

 


WARNING: Try to avoid floating-point numbers. If you really need to, be careful!

 

Input 

The first line contains an integer T (T$ \le$100), the number of test cases. Each test case contains three integers xyz (1$ \le$xy$ \le$10, 1$ \le$z$ \le$1000).

 

Output 

For each test case, print an integer, representing the amount of dollars that family A should get.

Sample Input 

2
5 4 90
8 4 123

Sample Output 

60
123

思路:主要要考虑到A,B除了帮第三个家庭分担外,本身自己也是要做工作的。所以5,4共做9小时,那么每个家庭要做3个小时。
则A帮C分担了2个小时,B帮C分担了1个小时,所以A获得90*2/3.
得出公式后时除法可能出错,要放到最后。

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <string>
 5 using namespace std;
 6 int x, y, z;
 7 int T;
 8 int main(){
 9     scanf("%d", &T);
10     while(T--){
11         scanf("%d%d%d", &x, &y, &z);
12         if(x > (x+y)/3){
13             printf("%d\n",(2*x-y)*z/(x+y));
14         }
15         else printf("0\n");
16     }
17     
18     return 0;
19 }

 



 

posted @ 2014-08-17 01:47  下周LGD该赢了吧  阅读(221)  评论(0编辑  收藏  举报