oj 2449: 三家人

题目要求
有三户人家共拥有一作花园,每户人家的太太均需帮忙整理花园。A太太工作了5天,B太太则工作了4天,才将花园整理完毕。C太太因为正身怀六甲无法加入她们的行列,便出了90元。请问这笔钱如何分给A、B二位太太较为恰当?A应得多少元?

90/(5+4)*5=$50元?如果这么想你就上当了!正确答案是60元。如果没想通的话再想想吧。下面回答一个一般性的问题:假定A太太工作了x天,B太太工作了y天,C太太出了z元,则A太太应得多少元?输入保证二位太太均应得到非负整数元钱。

Input
输入第一行为数据组数T (T<=20)。每组数据仅一行,包含三个整数x, y, z (1<=x, y<=10, 1<=z<=1000)。
Output
对于每组数据,输出一个整数,即A太太应得的金额(单位:元)。
Sample Input
Raw
2
5 4 90
8 4 123
Sample Output
Raw
60
123
题目是用A和B所帮助C工作的天数比例来计算每个人分到金额。
需要注意的是最后四舍五入的取证工作。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
    int t;
    float x, y, z;
    scanf("%d", &t);
    for (int i = 0; i < t; i++)
    {
        scanf("%f %f %f", &x, &y, &z);
        int m = floor(z * (x / ((x + y) / 3) - 1) + 0.5);
        printf("%d\n", m);
    }
    return 0;
}
发布了38 篇原创文章 · 获赞 27 · 访问量 3178

猜你喜欢

转载自blog.csdn.net/qq_45891413/article/details/105037499
OJ