- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc.cpp
More file actions
Latest commit
157 lines (132 loc) · 2.65 KB
/
Copy pathc.cpp
File metadata and controls
157 lines (132 loc) · 2.65 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
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
#include<bits/stdc++.h>
usingnamespacestd;
typedeflongdouble ld;
typedeflonglong ll;
longlongrdtsc() {
longlong tmp;
asm("rdtsc" : "=A"(tmp));
return tmp;
}
inlineintmyrand() {
#ifdef _WIN32
returnabs((rand() << 15) ^ rand());
#else
returnrand();
#endif
}
inlineintrnd(int x) {
returnmyrand() % x;
}
#ifdef LOCAL
#defineLLD"%lld"
#else
#ifdef _WIN32
#defineLLD"%I64d"
#else
#defineLLD"%lld"
#endif
#endif
#ifdef DEBUG
#defineeprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stdout)
#else
#defineeprintf(...) ;
#endif
#definepb push_back
#definemp make_pair
#definesz(x) ((int)(x).size())
#defineTASK"text"
voidprecalc() {
}
structPnt {
int x, y;
Pnt(): x(), y() {}
Pnt(int x, int y): x(x), y(y) {}
intdist(const Pnt & p) const {
returnabs(x - p.x) + abs(y - p.y);
}
};
structRide {
Pnt s, f;
int ts, tf;
int num;
voidread() {
scanf("%d%d%d%d%d%d", &s.x, &s.y, &f.x, &f.y, &ts, &tf);
}
booloperator <(const Ride & r) const {
return ts < r.ts;
}
};
constint maxn = 10010;
constint maxx = 10010;
constint maxf = 1010;
int r, c, f, n, b, t;
Ride rides[maxn];
boolread() {
if (scanf("%d%d%d%d%d%d", &r, &c, &f, &n, &b, &t) < 6) {
returnfalse;
}
for (int i = 0; i < n; ++i) {
rides[i].read();
rides[i].num = i;
}
returntrue;
}
vector<int> ans[maxf];
Pnt pos[maxf];
int tfree[maxf];
bool used[maxn];
voidsolve() {
for (int i = 0; i < f; ++i) {
ans[i].clear();
pos[i] = Pnt(0, 0);
tfree[i] = 0;
}
bool flag = true;
while (flag) {
flag = false;
for (int i = 0; i < f; i++) {
longlong dist = 1e9;
int opt = -1;
for (int j = 0; j < n; j++) {
if (!used[j]) {
int tm = max(tfree[i] + pos[i].dist(rides[j].s), rides[j].ts) + rides[j].s.dist(rides[j].f);
if (tm > rides[j].tf) continue;
if (pos[i].dist(rides[j].s) < dist) {
dist = pos[i].dist(rides[j].s);
opt = j;
}
}
}
if (opt != -1) {
flag = true;
ans[i].push_back(opt);
used[opt] = true;
tfree[i] = max(tfree[i] + pos[i].dist(rides[opt].s), rides[opt].ts) + rides[opt].s.dist(rides[opt].f);
pos[i] = rides[opt].f;
}
}
}
for (int i = 0; i < f; ++i) {
printf("%d", sz(ans[i]));
for (int j = 0; j < sz(ans[i]); ++j) {
printf(" %d", ans[i][j]);
}
printf("\n");
}
}
intmain() {
srand(rdtsc());
precalc();
freopen("c_no_hurry.in", "r", stdin);
freopen("c_no_hurry.out", "w", stdout);
while (true) {
if (!read()) {
break;
}
solve();
#ifdef DEBUG
eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
}
return0;
}