又是为自己的无知流泪的一年
- 一. 网易雷火笔试 300’
- 第一题26个字母分别算个斐波那契就行
- 第二题是个小贪心,按价值从大到小排个序,从最大的开始杀,杀这个数最好的时间就是他消失之前的那个时间点。
- 第三题一个模拟,按题目要求模拟就行
- 第四题四元数坑了我,最后20分钟调出了样例交上去还是0分,这题我实在没法手出样例算了,有时间好好再学学四元数,再调吧,放一个没A的代码省的删了。
// Didn't AC
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
using namespace std;
struct quaternion{
double t;
double x;
double y;
double z;
};
quaternion mul(quaternion left, quaternion right)
{
quaternion ans;
double d1, d2, d3, d4;
d1 = left.t * right.t;
d2 = -left.x * right.x;
d3 = -left.y * right.y;
d4 = -left.z * right.z;
ans.t = d1 + d2 + d3 + d4;
d1 = left.t * right.x;
d2 = right.t * left.x;
d3 = left.y * right.z;
d4 = -left.z * right.y;
ans.x = d1 + d2 + d3 + d4;
d1 = left.t * right.y;
d2 = right.t * left.y;
d3 = left.z * right.x;
d4 = -left.x * right.z;
ans.y = d1 + d2 + d3 + d4;
d1 = left.t * right.z;
d2 = right.t * left.z;
d3 = left.x * right.y;
d4 = -left.y * right.x;
ans.z = d1 + d2 + d3 + d4;
return ans;
}
quaternion VtoQ(double PosX, double PosY, double PosZ)
{
quaternion ans;
ans.t = 0.0;
ans.x = PosX;
ans.y = PosY;
ans.z = PosZ;
return ans;
}
int n;
vector<int> ch[2001];
quaternion node[2001];
quaternion coor[2001];
int fa[2001],root;
double Tdata[2001][20][10];
int m[2001];
void rotate(int p, quaternion q) {
quaternion qq;
qq.x = -q.x;
qq.y = -q.y;
qq.z = -q.z;
qq.t = q.t;
for (auto it : ch[p]) {
node[it] = mul(qq, node[it]);
node[it] = mul(node[it],q);
rotate(it, q);
}
return;
}
void getans(int p) {
for (auto it : ch[p]) {
coor[it].x = coor[p].x + node[it].x;
coor[it].y = coor[p].y + node[it].y;
coor[it].z = coor[p].z + node[it].z;
coor[it].t = coor[p].t + node[it].t;
getans(it);
}
}
quaternion line(quaternion q0, quaternion q1,double s) {
q0.t *= (1.0f-s);
q0.x *= (1.0f-s);
q0.y *= (1.0f-s);
q0.z *= (1.0f-s);
q1.t *= s;
q1.x *= s;
q1.y *= s;
q1.z *= s;
quaternion ans;
ans.x = q0.x + q1.x;
ans.y = q0.y + q1.y;
ans.z = q0.z + q1.z;
ans.t = q0.t + q1.t;
double xx = ans.x * ans.x;
double yy = ans.y * ans.y;
double zz = ans.z * ans.z;
double tt = ans.t * ans.t;
double ss = sqrt(xx + yy + zz + tt);
ans.t /= ss;
ans.x /= ss;
ans.y /= ss;
ans.z /= ss;
return ans;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int a;
double x, y, z;
cin >> a >> x >> y >> z;
if (a != -1) ch[a].push_back(i);
else root = i;
fa[i] = a;
node[i] = VtoQ(x, y, z);
}
for (int i = 0; i < n; i++) {
cin >> m[i];
for (int j = 0; j < m[i]; j++) {
for (int k = 0; k < 5; k++)
cin >> Tdata[i][j][k];
}
}
double T; cin >> T;
for (int i = 0; i < n; i++) {
double LastTime = 0;
quaternion LastQ;
for (int j = 0; j < m[i]; j++) {
double time = Tdata[i][j][0];
quaternion q = { Tdata[i][j][2], Tdata[i][j][3], Tdata[i][j][4], Tdata[i][j][1] };
if (time <= T) {
rotate(i, q);
}
else {
quaternion temp = line(LastQ, q, (T - LastTime) / (time-LastTime));
rotate(i, temp);
break;
}
LastTime = time;
LastQ = q;
}
}
getans(root);
for (int i = 0; i < n; i++) {
printf("%.2lf %.2lf %.2lf\n", coor[i].x, coor[i].y, coor[i].z);
}
return 0;
}