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;
}