UVA12502-Three Families

本文介绍了一种算法,用于解决三个家庭共同维护花园时清洁费用的公平分配问题。通过计算每个家庭为缺失的家庭额外付出的工作量,该算法确保了补偿的合理性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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<=100),the number of test cases,Each test case contains three integers

x,y,z(1<=x,y<=10,1<=z<=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

//注意看清要求,此题是要求三个家庭共同打扫花园,所以本来一个家庭需要打扫3个小时
所以case1中A帮C打扫两个小时,B帮C打扫1个小时,A分60,B分30
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int T,n,m;
    double l;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%lf",&n,&m,&l);
        double x,xx;
        x=l/(n+m);
        xx=x*(n+n-m);
        printf("%0.lf\n",xx);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值