首页 > 其他 > 详细

UVA 12502 Three Families (A)

时间:2014-08-17 02:26:01      阅读:274      评论:0      收藏:0      [点我收藏+]
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 (Tbubuko.com,布布扣100), the number of test cases. Each test case contains three integers xyz (1bubuko.com,布布扣xybubuko.com,布布扣10, 1bubuko.com,布布扣zbubuko.com,布布扣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 }

 



 

UVA 12502 Three Families (A),布布扣,bubuko.com

UVA 12502 Three Families (A)

原文:http://www.cnblogs.com/titicia/p/3917221.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!