-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1052.cpp
More file actions
83 lines (79 loc) · 2.29 KB
/
1052.cpp
File metadata and controls
83 lines (79 loc) · 2.29 KB
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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#define LEFT 0
#define RIGHT 1
#define DOWN 1
#define UNDOWN 0
using namespace std;
struct domino {
int at;
int tall;
};
int linear[1000001];
int main() {
int n,max = 0;
queue<int> q;
scanf("%d",&n);
domino *array = (domino*)calloc(sizeof(domino), n+1);
for (int i = 1; i <= n; ++i) {
scanf("%d %d",&array[i].at,&array[i].tall);
linear[array[i].at] = i;
if (max < array[i].at) {
max = array[i].at;
}
}
int maxDominoDown = 0;
int dominoDown, leftOrRight;
bool *status;
for (int i = 1; i <= n; ++i) {
//Left
status = (bool *)calloc(sizeof(bool), n+1);
int count = 0;
q.push(i);
while (!q.empty()) {
int processDomino = q.front();
status[processDomino] = DOWN;
q.pop();
++count;
int from = array[processDomino].at;
int to = (array[processDomino].at-array[processDomino].tall+1 < 0)?0:array[processDomino].at-array[processDomino].tall+1;
for (int i = from; i >= to; --i) {
if (linear[i] != 0 && status[i] != DOWN) {
q.push(linear[i]);
}
}
}
if (count > maxDominoDown) {
maxDominoDown = count;
dominoDown = i;
leftOrRight = LEFT;
}
delete [] status;
//Right
status = (bool *)calloc(sizeof(bool), n+1);
count = 0;
q.push(i);
while (!q.empty()) {
int processDomino = q.front();
status[processDomino] = DOWN;
q.pop();
++count;
int from = array[processDomino].at;
int to = (array[processDomino].at+array[processDomino].tall-1 > max)?max:array[processDomino].at+array[processDomino].tall-1;
for (int i = from; i <= to; ++i) {
if (linear[i] != 0 && status[i] != DOWN) {
q.push(linear[i]);
}
}
}
if (count > maxDominoDown) {
maxDominoDown = count;
dominoDown = i;
leftOrRight = RIGHT;
}
delete [] status;
}
printf("%d %c",dominoDown,(leftOrRight == LEFT)?'L':'R');
}