-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.cpp
170 lines (141 loc) · 5.21 KB
/
source.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <iostream>
#include <cmath>
#include <cassert>
#include <iomanip>
#include "funkcja.h"
class Jet {
double f, dx, dy, dxx, dxy, dyy;
public:
Jet() : f(0.0), dx(0.0), dy(0.0), dxx(0.0), dxy(0.0), dyy(0.0) {}
Jet(const double value,
const double dx,
const double dy,
const double dxx,
const double dxy,
const double dyy) : f(value), dx(dx), dy(dy), dxx(dxx), dxy(dxy), dyy(dyy) {};
Jet(const Jet& jet) : f(jet.f), dx(jet.dx), dy(jet.dy), dxx(jet.dxx), dxy(jet.dxy), dyy(jet.dyy) {};
friend std::ostream &operator<<(std::ostream &ostream, const Jet& jet) {
ostream << (jet.f == -0 ? 0 : jet.f) << " "
<< (jet.dx == -0 ? 0 : jet.dx) << " "
<< (jet.dy == -0 ? 0 : jet.dy) << " "
<< (jet.dxx == -0 ? 0 : jet.dxx) << " "
<< (jet.dxy == -0 ? 0 : jet.dxy) << " "
<< (jet.dyy == -0 ? 0 : jet.dyy);
return ostream;
}
// operator przypisania
inline Jet &operator=(const Jet& jet) = default;
// negacja
inline Jet operator-() const {
return Jet(-f, -dx, -dy, -dxx, -dxy, -dyy);
}
// c - jet
inline friend Jet operator-(const double& c, const Jet& jet) {
return Jet(c, 0., 0., 0., 0., 0.) - jet;
}
// jet - c
inline friend Jet operator-(const Jet& jet, const double& c) {
return Jet(jet.f - c, jet.dx, jet.dy, jet.dxx, jet.dxy, jet.dyy);
}
// jet - jet
inline friend Jet operator-(const Jet& u, const Jet& v) {
return Jet(u.f - v.f, u.dx - v.dx, u.dy - v.dy,
u.dxx - v.dxx, u.dxy - v.dxy, u.dyy - v.dyy);
}
// c + jet
inline friend Jet operator+(const double& c, const Jet& jet) {
return Jet(c, 0., 0., 0., 0., 0.) + jet;
}
// jet + c
inline friend Jet operator+(const Jet& jet, const double& c) {
return Jet(jet.f + c, jet.dx, jet.dy, jet.dxx, jet.dxy, jet.dyy);
}
// jet + jet
inline friend Jet operator+(const Jet& u, const Jet& v) {
return Jet(u.f + v.f, u.dx + v.dx, u.dy + v.dy,
u.dxx + v.dxx, u.dxy + v.dxy, u.dyy + v.dyy);
}
// jet * jet
inline friend Jet operator*(const Jet& u, const Jet& v) {
return Jet( u.f * v.f,
u.f * v.dx + u.dx * v.f,
u.f * v.dy + u.dy * v.f,
u.f * v.dxx + 2 * u.dx * v.dx + u.dxx * v.f,
u.f * v.dxy + u.dx * v.dy + u.dy * v.dx + u.dxy * v.f,
u.f * v.dyy + 2 * u.dy * v.dy + u.dyy * v.f);
}
// jet * c
inline friend Jet operator*(const Jet& jet, const double& c) {
return c * jet;
}
// c * jet
inline friend Jet operator*(const double& c, const Jet& jet) {
return jet * Jet(c, 0., 0., 0., 0., 0.);
}
// jet / jet
inline friend Jet operator/(const Jet& u, const Jet& v) {
double quotient = u.f / v.f;
double res_dx = (u.dx - (quotient * v.dx)) / v.f;
double res_dy = (u.dy - (quotient * v.dy)) / v.f;
double neg_v = -v.f;
return Jet(quotient,
res_dx,
res_dy,
(2 * v.dx * res_dx + quotient * v.dxx -u.dxx) / neg_v,
(v.dx * res_dy + v.dy * res_dx + quotient * v.dxy - u.dxy) / neg_v,
(2 * v.dy * res_dy + quotient * v.dyy - u.dyy) / neg_v);
}
// jet / c
inline friend Jet operator/(const Jet& jet, const double& c) {
return (jet / Jet(c, 0., 0., 0., 0., 0.));
}
// c / jet
inline friend Jet operator/(const double& c, const Jet& jet) {
return Jet(c / jet.f, 0., 0., 0., 0., 0.);
}
inline friend Jet sin(const Jet& jet) {
double sine = std::sin(jet.f);
double cosine = std::cos(jet.f);
return Jet(sine,
jet.dx * cosine,
jet.dy * cosine,
jet.dxx * cosine - jet.dx * jet.dx * sine,
jet.dxy * cosine - jet.dx * jet.dy * sine,
jet.dyy * cosine - jet.dy * jet.dy * sine);
}
inline friend Jet cos(const Jet& jet) {
double sine = std::sin(jet.f);
double cosine = std::cos(jet.f);
return Jet(cosine,
-jet.dx * sine,
-jet.dy * sine,
-(jet.dxx * sine + jet.dx * jet.dx * cosine),
-(jet.dxy * sine + jet.dx * jet.dy * cosine),
-(jet.dyy * sine + jet.dy * jet.dy * cosine));
}
inline friend Jet exp(const Jet& jet) {
double e = std::exp(jet.f);
return Jet(e,
jet.dx * e,
jet.dy * e,
jet.dxx * e + jet.dx * jet.dx * e,
jet.dxy * e + jet.dx * jet.dy * e,
jet.dyy * e + jet.dy * jet.dy * e);
}
};
int main() {
unsigned int M;
std::cin >> M;
assert (M < 1000000 and M > 0);
double x0, y0;
std::cout << std::fixed << std::setprecision(15);
for (int i = 0; i < M; ++i) {
std::cin >> x0 >> y0;
Jet jet_x(x0, 1., 0., 0., 0., 0.);
Jet jet_y(y0, 0., 1., 0., 0., 0.);
Jet res = funkcja(jet_x, jet_y);
std::cout << res;
std::cout << std::endl;
}
return 0;
}