50163. Seat Assignment
難度:3.8/5 Used Time: 27:48
沒事不要亂開uint8_t
,他最大256而已。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#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
typedef struct{
int c;
int row;
int col;
} pos;
int n;
uint8_t car[1000][20][5] = {0};
pos single = {0};
pos double1 = {0};
pos double2 = {0};
void step(pos* p){
p->col++;
if(p->col == 5) p->col = 0, p->row++;
if(p->row == 20) p->row = 0, p->c++;
}
int is_ocp(pos* p){
return car[p->c][p->row][p->col];
}
void set_ocp(pos* p){
car[p->c][p->row][p->col] = 1;
}
void print_pos(pos* p){
printf("%d %d %d", p->c + 1, p->row + 1, p->col + 1);
}
int is_together(pos* a, pos* b){
if(a->c != b->c) return 0;
if(a->row != b->row) return 0;
if(b->col - a->col != 1) return 0;
if(a->col == 2) return 0;
return 1;
}
int is_oob(pos* p){
return p->c >= n;
}
void init(){
scanf("%d", &n);
memset(car, 0, sizeof(uint8_t) * 20 * 5);
single.c = 0, single.row = 0, single.col = 0;
double1.c = 0, double1.row = 0, double1.col = 0;
double2.c = 0, double2.row = 0, double2.col = 1;
}
void deal_single(){
while(is_ocp(&single)) step(&single);
set_ocp(&single);
print_pos(&single);
}
int deal_double(){
while(1){
if(is_oob(&double1) || is_oob(&double2)) return -1;
if(!is_ocp(&double1) && !is_ocp(&double2) && is_together(&double1, &double2)) break;
step(&double1);
step(&double2);
}
set_ocp(&double1);
set_ocp(&double2);
print_pos(&double1); printf(" ");
print_pos(&double2); printf("\n");
return 1;
}
int main(){
init();
int req;
while(scanf("%d", &req) != EOF){
if(req == 1){
deal_single();
printf("\n");
}
else{
int rtv = deal_double();
if(rtv == -1){
deal_single(); printf(" ");
deal_single(); printf("\n");
}
}
}
}