A--The Voice of China
时间: 1ms 内存:128M
描述:
The Fourth Voice of China is coming. It will apply a new rule to determine the champion. There are four judges in charge of scoring for the singer, each judge giving a score Si and a weight Wi, the weighted score of each judge is Si*Wi. For each singer, the final score is the sum of four judges’ weighted score. Can you write a program to calculate the final score?
输入:
The first line of the input contains two integers N and M(1<=N<=20, 1<=M<=50) . N means the number of test cases and M means the number of candidates. The second line cinsists of 4 decimals (0<w1, w2, w3, w4<1) which represent the judges’ weights . Then the follows are M lines, each line consisting of 4 integers (0<=s1, s2, s3, s4<= 100) which represent judges’ scores.
输出:
For each case, output the integer part of the final scoreof every candidates for each line.
示例输入:
1 2
0.2 0.3 0.1 0.4
78 88 79 80
83 89 87 79
示例输出:
81
83
提示:
参考答案(内存最优[920]):
/*1 2
0.2 0.3 0.1 0.4
78 88 79 80
83 89 87 79
*/
#include <stdio.h>
int main()
{
int n,m;
float w1,w2,w3,w4;
int num1,num2,num3,num4;
int i,j;
int a[25][55];
scanf("%d %d",&n,&m);
scanf("%f %f %f %f",&w1,&w2,&w3,&w4);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d %d %d %d",&num1,&num2,&num3,&num4);
a[i][j]=num1*w1+num2*w2+num3*w3+num4*w4;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
printf("%d\n",a[i][j]);
}
return 0;
}
参考答案(时间最优[0]):
#include <iostream>
using namespace std;
int main()
{
int n,m,sum;
float p1,p2,p3,p4;
int a,b,c,d;
cin>>n>>m;
while(n--)
{
cin>>p1>>p2>>p3>>p4;
while(m--)
{
cin>>a>>b>>c>>d;
sum=p1*a+p2*b+p3*c+p4*d;
cout<<sum<<endl;
}
}
return 0;
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。