csu 1345: Grayscale

1345: Grayscale

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 272   Solved: 94
[ Submit][ Status][ Web Board]

Description

    We could represent a color point by a triple (RGB) (0 <= RGB <= 255). The grayscale of it could be calculated by this formula:
    Grayscale = R * 0.299 + G * 0.587 + B * 0.114

Input

    The first line has an integer T (1 <= T <= 100), means there are T test cases.
    For each test case, there are three integers RGB (0 <= RGB <= 255) in one line, which have the same meaning as above.

Output

    For each test case, print an integer in one line, indicates the integer part of the grayscale of this color point.

Sample Input

4
0 0 0
100 0 0
30 40 50
255 255 255

Sample Output

0
29
38
255

HINT

Source

中南大学第一届长沙地区程序设计邀请赛

分析:
中南大学第一届长沙地区程序设计邀请赛水题。直接带入公式后向下取整就是答案。
ac代码:
#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    int t;
    double r,g,b;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf",&r,&g,&b);
        double ans=r*0.299+g*0.587+b*0.114;
        printf("%.0lf\n",floor(ans));
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值