50201. Origami

難度:3.8/5 Used Time: 18:11

Diag的構造又要先想好再寫。

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
#include <stdio.h>
#include <stdlib.h>

int r, c;
int arr[640][640] = {0};

void down(int x){
int temp = x - 1;
for(int i = x; i < 2 * x; i++){
for(int j = 0; j < c; j++){
arr[i][j] += arr[temp][j];
}
temp--;
}
for(int i = 0; i < r - x; i++){
for(int j = 0; j < c; j++){
arr[i][j] = arr[i + x][j];
}
}
r -= x;
}
void left(int x){
int temp = c - 1;
for(int j = c - 2 * x; j < c - x; j++){
for(int i = 0; i < r; i++){
arr[i][j] += arr[i][temp];
}
temp--;
}
c -= x;
}
void diag(int s){
int x = 0, y = c - s;
for(int i = 0; i < s; i++){
int now_x = x + 1, now_y = y + 1;
while(now_y < c){
arr[now_x][y]+= arr[x][now_y];
arr[x][now_y] = 0;
now_x++, now_y++;
}
x++, y++;
}
}

void print_board(){
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
printf("%d%c", arr[i][j], (j == c - 1) ? '\n' : ' ');
}
}
}


int main(){
scanf("%d %d", &r, &c);
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
scanf("%d", &arr[i][j]);
}
}

int t, x;
while(scanf("%d %d", &t, &x) != EOF){
if(t == 1) down(x);
if(t == 2) left(x);
if(t == 3) diag(x);
}
print_board();
}


50201. Origami
https://aaronlin1229.github.io/judgegirl_50201/
Author
Akizumi
Posted on
July 17, 2023
Licensed under