zoukankan      html  css  js  c++  java
  • 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.

    $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  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
    ",mu);
        }
    
        return 0;
    }
    


  • 相关阅读:
    tcpreplay安装使用经验
    Linux 性能优化之 IO 子系统 系列 图
    深入理解Fsync----JBD内核调试 专业打杂程序员 @github yy哥
    LINUX 文件系统JBD ----深入理解Fsync
    通过查看mysql 配置参数、状态来优化你的mysql
    linux IO 内核参数调优 之 原理和参数介绍
    Mysql参数详解
    Mysql show Status参数详解
    MYSQL: Handler_read_%参数说明
    mysql的优化措施,从sql优化做起
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3246942.html
Copyright © 2011-2022 走看看