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


  • 相关阅读:
    Java线程基础(二)
    Java线程基础(一)
    泛型集合List的详细用法
    Java中日期格式(String、Date、Calendar)的相互转换
    重写Java中包装类的方法
    Java的集合框架(第一次小结)
    node.js 调用mysql 数据库
    win10 系统解决mysql中文乱码问题
    vue-echarts图表
    文件上传的几个例子
  • 原文地址:https://www.cnblogs.com/titicia/p/3917221.html
Copyright © 2011-2022 走看看