1345: Grayscale
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 272 Solved: 94
[ Submit][ Status][ Web Board]
Description
We could represent a color point by a triple (R, G, B) (0 <= R, G, B <= 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 R, G, B (0 <= R, G, B <= 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;
}
#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;
}
本文介绍了一种将RGB颜色转换为灰度值的算法,并通过具体实例演示了如何使用该算法进行计算。文章提供了一个简单的C++实现示例,帮助读者理解并应用此算法。
406

被折叠的 条评论
为什么被折叠?



