Three Families

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3946


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.php

$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.ios

 


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

 

Input 

The first line contains an integer  T  ( T$ \le$100 ), the number of test cases. Each test case contains three integers  x y z  ( 1$ \le$x y$ \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

 



Problemsetter: Rujia Liu, Special Thanks: Feng Chen, Md. Mahbubul Hasann, Youzhi Bao


這個題就以純粹數學題,能想通公式則不要10行代碼解決,想不到公式想死都作不出來。。。

這題是2012年湖南省省賽簽到題。。。。。

思路:他們三家共用一個花園,仍是平局分的,三家工做效率相同,那麼也就是說三家修剪草坪的總時間相同,如今只有2家人作3家人的活。
則每家修剪草坪的時間爲:  (x+y)/3
由此可知A,B兩家給C修剪的時間分別爲:x-(x+y)/3   和  y-(x+y)/3
C給A、B支付報酬是按比例支付的,則A的報酬爲:z*(x-(x+y)/3)/(x-(x+y)/3+y-(x+y)/3)

AC代碼:
#include<iostream>
#include<cstdio>

int main()
{
    int t,x,y,z,mu;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&x,&y,&z);
        mu = z*(x-(x+y)/3)/(x-(x+y)/3+y-(x+y)/3);
        printf("%d\n",mu);
    }

    return 0;
}
相關文章
相關標籤/搜索