• 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
    ",(2*x-y)*z/(x+y));
    14         }
    15         else printf("0
    ");
    16     }
    17     
    18     return 0;
    19 }


  • 相关阅读:
    accpet和connect设置超时
    两个模块的函数如何相互调用?
    有头结点的双向链表
    信号量PV操作实现进程间同步与互斥
    linux read write函数
    函数用指针传参挂死分析
    TCP/IP为什么需要四次握手和三次挥手
    负数在内存中的表示
    malloc的堆内存挂死原因;负数的表示
    Makefiel----no rule to make target 错误问题
  • 原文地址:https://www.cnblogs.com/titicia/p/3917221.html
Copyright © 2020-2023  润新知