b426. 宇宙光明體

contents

  1. 1. Problem
  2. 2. Sample Input
  3. 3. Sample Output
  4. 4. Solution

Problem

模擬兩張圖片的合成。

將前景圖片疊在背景圖片之上,按照權重比例來融合重疊部分得像素。

Sample Input

1
2
3
4
5
0 0 0.5
1 1
255 255 255
1 1
0 0 0

Sample Output

1
2
1 1
128 128 128

Solution

原來是宇宙光明體,還以為是宇宙大覺者呢。

按照公式純模擬即可。

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
#include <bits/stdc++.h>
using namespace std;
const double eps = 0;
class IMAGE {
public:
struct Pixel {
long double r, g, b, a;
Pixel(long double x = 0, long double y = 0, long double z = 0, long double w = 0):
r(x), g(y), b(z), a(w) {}
void read() {
int p1, p2, p3;
scanf("%d %d %d", &p1, &p2, &p3);
r = p1, g = p2, b = p3;
}
Pixel operator-(const Pixel &x) const {
return Pixel(r-x.r, g-x.g, b-x.b, a-x.a);
}
Pixel operator+(const Pixel &x) const {
return Pixel(r+x.r, g+x.g, b+x.b, a+x.a);
}
Pixel operator*(const long double x) const {
return Pixel(r*x, g*x, b*x, a*x);
}
Pixel operator/(const long double x) const {
return Pixel(r/x, g/x, b/x, a/x);
}
void print() {
double p1 = r, p2 = g, p3 = b, p4 = a;
printf("%.0lf %.0lf %.0lf", p1 + eps, p2 + eps, p3 + eps);
}
};
int W, H;
static const int MAXN = 256;
Pixel data[MAXN][MAXN];
void read() {
scanf("%d %d", &W, &H);
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
data[i][j].read();
}
void add(IMAGE &other, int X, int Y, double OPACITY) {
for (int i = 0; i < other.H && i+X < H; i++) {
for (int j = 0; j < other.W && j+Y < W; j++) {
if (i+X >= 0 && j+Y >= 0)
data[i+X][j+Y] = other.data[i][j] * OPACITY + data[i+X][j+Y] * (1 - OPACITY);
}
}
}
void print() {
printf("%d %d\n", W, H);
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
data[i][j].print(), printf("%c", j == W-1 ? '\n' : ' ');
}
} back, fore;
int main() {
double OPACITY;
int X, Y;
scanf("%d %d %lf", &X, &Y, &OPACITY);
fore.read();
back.read();
back.add(fore, Y, X, OPACITY);
back.print();
return 0;
}