题目
样例输入
11
5
3
5
3
0.6 0.2 0.2 0.01 0.02 0.15 0.37 0.45 0.4 0.3 0.3
0.8 0.2 0 0 0
0.1 0.4 0.3 0.2 0
0.1 0.3 0.3 0.3 0
0.1 0.7 0.2 0 0.4
0.1 0.8 0.1 0 0
0.1 0.3 0.5 0.1 0
0.1 0.3 0.4 0.2 0
0 0 0.3 0.6 0.1
0.5 0.4 0.1 0 0
0.2 0.6 0.2 0 0
0.2 0.5 0.2 0.1 0
样例输出
0.6967
0.1543
0.1490
0.0134
0.0261
0.1446
0.3256
0.4903
0.4094
0.3143
0.2763
题解
题目写的简短且不清楚,属于水平很差的一类题目,完全没有解释清楚公式的运用,举的例子也不是很清楚,需要仔细地猜测
拿到题目首先把问题原子化,重载了乘号和加号,用来匹配运算,然后写了一个将数组中每个数平方和开方的函数,又借用了上一题的归一化函数,至此积木已经完善,可以开始拼接了
接收完数据后,首先要做的就是分组实现,每一组的数量不同而且已知,这就好办了,使用头尾游标即可
分别利用公式计算出来即可,难度很低
代码
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
vector<double> operator*(const vector<double>& a, double& b)
{
vector<double> res;
for (auto i : a)
{
res.push_back(i * b);
}
return res;
}
vector<double> operator+(const vector<double>& a, const vector<double>& b)
{
vector<double> res;
res.resize(a.size());
for (int i = 0; i < a.size(); i++)
{
res[i] = a.at(i) + b.at(i);
}
return res;
}
double SpCompute(vector<double> a)
{
double sum = 0;
for (auto i : a)
{
sum += i * i;
}
return sqrt(sum);
}
//归一化
void NormalMatrix(vector<double>& mat)
{
double sum = 0;
for (auto i : mat)
{
sum += i;
}
auto i = mat.begin();
while (i != mat.end())
{
*i = *i / sum;
i++;
}
}
int main()
{
int n;
cin >> n;
int m;
cin >> m;
int attr[3];
for (int i = 0; i < 3; i++)
{
cin >> attr[i];
}
vector<double> forward_p;
for (int i = 0; i < n; i++)
{
double tem;
cin >> tem;
forward_p.push_back(tem);
}
vector<vector<double>> mat_r;
for (int i = 0; i < n; i++)
{
vector<double> tem1;
for (int j = 0; j < m; j++)
{
double tem2;
cin >> tem2;
tem1.push_back(tem2);
}
mat_r.push_back(tem1);
}
vector<double> res;
int fir = 0;
int tal = fir + attr[0];
for (int i = 0; i < 3; i++)
{
vector<double> res_f1;
vector<double> tem1(m);
for (int j = fir; j < tal; j++)
{
tem1 = tem1 + mat_r.at(j) * forward_p.at(j);
}
double tem2 = SpCompute(tem1);
for (int j = fir; j < tal; j++)
{
res_f1.push_back(SpCompute(mat_r.at(j) * forward_p.at(j)) / tem2);
}
NormalMatrix(res_f1);
for (auto j : res_f1)
{
res.push_back(j);
}
if (i < 2)
{
fir += attr[i];
tal = fir + attr[i + 1];
}
}
//输出
for (auto i : res)
{
printf_s("%.4f\n", i);
}
return 0;
}