Acm

poj3760魔兽世界

静不下心来只好敲敲大模拟

Posted by Tivility on October 23, 2018

题目链接: 魔兽世界(修订版)

  • 一句话题解: 大模拟, 对照着题意敲就是了
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
using namespace std;
const int MAX = 55;
const int bornorder[3][5] = {0, 0, 0, 0, 0, 3, 4, 5, 2, 1, 4, 1, 2, 3, 5};
int m, n, t, _, __;
int Elements[10], Forces[10], cnt[3];
int charitor, hh, mm, pstime;
string group_name[3] = {"", "red", "blue"};
string type_name[6]  = {"", "dragon", "ninja", "iceman", "lion", "wolf"};
struct Character {
    int type; // 1: dragon, 2: ninja, 3: iceman, 4: lion, 5: wolf;
    int group; // 1: red, 2: blue;
    int elements, forces, id, cnt;
    void born(int group, int type, int id) {
        this->id        = id;           this->cnt       = 0;
        this->type      = type;         this->group     = group;
        this->forces    = Forces[type]; this->elements  = Elements[type];
    }
    void output() {
        cout << group_name[group] << " " << type_name[type] << " " << id;
    }
    void outdata() {
        cout << " with " << elements <<
            " elements and force " << forces << endl;
    }
}character[MAX];
struct City {
    int elements, charid[3], flag, cnt;
    bool killed;
    void init() {
        cnt = flag = elements = 0;
        killed = false;
        charid[0] = charid[1] = charid[2] = -1;
        return ;
    }
}city[MAX];
void init() {
    for (int i = 0; i <= n + 1; ++i)
        city[i].init();
    city[0].elements = city[n + 1].elements = m;
    hh = mm = charitor = cnt[1] = cnt[2] = 0;
    return ;
}
void outputtime() {
    if (hh < 10) cout << "00";
    else if (hh < 100) cout << "0";
    cout << hh << ":";
    if (mm == 0) cout << "00 ";
    else cout << mm << " ";
    return ;
}
void tryborn(int group) {
    int cityid = 0;
    if (group == 2)
        cityid = n + 1;
    int nxt_to_born = bornorder[group][ cnt[group] % 5 ];
    if (city[cityid].elements >= Elements[nxt_to_born]) {
        cnt[group]++;
        city[cityid].elements -= Elements[nxt_to_born];
        character[charitor].born(group, nxt_to_born, cnt[group]);
        city[cityid].charid[group] = charitor++;
        outputtime(); character[city[cityid].charid[group]].output();
        cout << " born" << endl;
    }
    return ;
}
void ck_iceman(int preid) {
    if (character[preid].type == 3) {
        if (character[preid].cnt & 1) {
            character[preid].elements = max(1, character[preid].elements - 9);
            character[preid].forces  += 20;
        }
        character[preid].cnt++;
    }
    return ;
}
void check_city(int n) {
    int preid = city[n - 1].charid[1];
    if (preid != -1) {
        ck_iceman(perid); outputtime(); character[preid].output();
        cout << " marched to city " << n;
        character[preid].outdata();
    }
    preid = city[n + 1].charid[2];
    if (preid != -1) {
        ck_iceman(perid); outputtime(); character[preid].output();
        cout << " marched to city " << n;
        character[preid].outdata();
    }
    return ;
}
bool fight(int redfirst, int cityid) {
    // notice: dragon(1), ninja(2), lion(4), wolf(5)
    int fst = city[cityid].charid[2], sec = city[cityid].charid[1];
    if (redfirst) swap(fst, sec);
    bool ret = false, secwin = true;
    outputtime(); character[fst].output();
    cout << " attacked "; character[sec].output();
    cout << " in city " << cityid; character[fst].outdata();
    if (character[sec].elements <= character[fst].forces) {
        outputtime(); character[sec].output();
        ret = true, secwin = false;
        cout << " was killed in city " << cityid << endl;
        if (character[fst].type == 1) { // dragon, yelled
            outputtime(); character[fst].output();
            cout << " yelled in city " << cityid << endl;
        }
        outputtime(); character[fst].output();
        cout << " earned " << city[cityid].elements <<
            " elements for his headquarter" << endl;
        if (character[fst].type == 5) { // wolf
            if (character[fst].cnt & 1) {
                character[fst].elements *= 2;
                character[fst].forces   *= 2;
            }
            character[fst].cnt++;
        }
        if (character[sec].type == 4) // lion
            character[fst].elements += character[sec].elements;
    } else if (character[sec].type != 2) {
        outputtime(); character[sec].output();
        cout << " fought back against ";
        character[fst].output();
        cout << " in city " << cityid << endl;
        if (character[fst].elements <= (character[sec].forces / 2)) {
            ret = true;
            outputtime(); character[fst].output();
            cout << " was killed in city " << cityid << endl;
            outputtime(); character[sec].output();
            cout << " earned " << city[cityid].elements <<
                " elements for his headquarter" << endl;
            if (character[fst].type == 4) // lion
                character[sec].elements += character[fst].elements;
        } else if (character[fst].type == 1) { // dragon, yelled
            outputtime(); character[fst].output();
            cout << " yelled in city " << cityid << endl;
        }
    } else if (character[fst].type == 1) { // dragon, yelled
        outputtime(); character[fst].output();
        cout << " yelled in city " << cityid << endl;
    }
    character[sec].elements -= character[fst].forces;
    if (secwin && character[sec].type != 2) character[fst].elements -= (character[sec].forces / 2);
    if (ret) { //flag
        int winid = 0;
        if (redfirst) {
            if (secwin) winid = 2;
            else winid = 1;
        } else {
            if (secwin) winid = 1;
            else winid = 2;
        }
        if (winid == 1) {
            city[cityid].charid[2] = -1;
            if (city[cityid].cnt < 0)
                city[cityid].cnt = 0;
            city[cityid].cnt++;
            if (city[cityid].cnt == 2 && city[cityid].flag != 1) {
                city[cityid].flag = 1;
                outputtime();
                cout << "red flag raised in city " << cityid << endl;
            }
        } else{
            city[cityid].charid[1] = -1;
            if (city[cityid].cnt > 0)
                city[cityid].cnt = 0;
            city[cityid].cnt--;
            if (city[cityid].cnt == -2 && city[cityid].flag != 2) {
                city[cityid].flag = 2;
                outputtime();
                cout << "blue flag raised in city " << cityid << endl;
            }
        }
    } else {
        city[cityid].cnt = 0;
    }
    return ret;
}
void judge() {
    pstime = hh = mm = 0;
    bool bk = false;
    while (pstime <= t) {
        // :00 try to born
        tryborn(1);
        tryborn(2);
        mm += 10;
        pstime += 10;
        if (pstime > t) break;
        // :10 move
        if (city[1].charid[2] != -1) {
            int preid = city[1].charid[2];
            if (character[preid].type == 3) {
                if (character[preid].cnt & 1) {
                    character[preid].elements = max(1, character[preid].elements - 9);
                    character[preid].forces  += 20;
                }
                character[preid].cnt++;
            }
            outputtime(); character[city[1].charid[2]].output();
            cout << " reached red headquarter";
            character[city[1].charid[2]].outdata();
            if (city[0].charid[2] != -1) {
                outputtime();
                cout << "red headquarter was taken" << endl;
                //break;
                bk = true;
            }
        }
        for (int i = 1; i <= n; ++i)
            check_city(i);
        if (city[n].charid[1] != -1) {
            int preid = city[n].charid[1];
            if (character[preid].type == 3) {
                if (character[preid].cnt & 1) {
                    character[preid].elements = max(1, character[preid].elements - 9);
                    character[preid].forces  += 20;
                }
                character[preid].cnt++;
            }
            outputtime(); character[city[n].charid[1]].output();
            cout << " reached blue headquarter";
            character[city[n].charid[1]].outdata();
            if (city[n + 1].charid[1] != -1) {
                outputtime(); cout << "blue headquarter was taken" << endl;
                //break;
                bk = true;
            }
        }
        for (int i = 0; i <= n; ++i)
            if (city[i + 1].charid[2] != -1) {
                city[i].charid[2] = city[i + 1].charid[2]; city[i + 1].charid[2] = -1;
            }
        for (int i = n + 1; i >= 1; --i)
            if (city[i - 1].charid[1] != -1) {
                city[i].charid[1] = city[i - 1].charid[1]; city[i - 1].charid[1] = -1;
            }
        mm += 10; pstime += 10;
        if (pstime > t || bk) break;
        // :20 city create elements
        for (int i = 1; i <= n; ++i)
            city[i].elements += 10;
        mm += 10; pstime += 10;
        if (pstime > t) break;
        // :30 take elements
        for (int i = 1; i <= n; ++i) {
            if (city[i].charid[1] != -1 && city[i].charid[2] == -1) {
                outputtime();
                character[city[i].charid[1]].output();
                cout << " earned " << city[i].elements <<
                    " elements for his headquarter" << endl;
                city[0].elements += city[i].elements;
                city[i].elements  = 0;
            } else if (city[i].charid[2] != -1 && city[i].charid[1] == -1) {
                outputtime();
                character[city[i].charid[2]].output();
                cout << " earned " << city[i].elements <<
                    " elements for his headquarter" << endl;
                city[n + 1].elements += city[i].elements;
                city[i].elements      = 0;
            }
        }
        mm += 10; pstime += 10;
        if (pstime > t) break;
        // :40 fight
        for (int i = 1; i <= n; ++i) {
            if (city[i].charid[1] != -1 && city[i].charid[2] != -1) {
                bool redfirst = true;
                if (city[i].flag == 2) {
                    redfirst = false;
                } else if (city[i].flag == 0 && ((i & 1) == 0)) {
                    redfirst = false;
                }
                if (fight(redfirst, i)) {
                    city[i].killed = true;
                }
            }
        }
        for (int i = 1; i <= n; ++i) {
            if (city[i].killed && city[i].charid[2] != -1) {
                if (city[n + 1].elements < 8)
                    break;
                city[n + 1].elements -= 8;
                character[city[i].charid[2]].elements += 8;
            }
        }
        for (int i = n; i >= 1; --i) {
            if (city[i].killed && city[i].charid[1] != -1) {
                if (city[0].elements < 8)
                    break;
                city[0].elements -= 8;
                character[city[i].charid[1]].elements += 8;
            }
        }
        for (int i = 1; i <= n; ++i) {
            if (city[i].killed) {
                if (city[i].charid[1] != -1)
                    city[0].elements += city[i].elements;
                else
                    city[n + 1].elements += city[i].elements;
                city[i].elements = 0;
                city[i].killed = false;
            }
        }
        mm += 10; pstime += 10;
        if (pstime > t) break;
        // :50 headquarter announce the elements
        outputtime(); cout << city[0].elements << " elements in red headquarter" << endl;
        outputtime(); cout << city[n + 1].elements << " elements in blue headquarter" << endl;
        pstime += 10; mm = 0; hh++;
    }
    return ;
}
int main() {
    for (__ = (bool)(cin >> _); __ <= _; ++__) {
        cin >> m >> n >> t;
        for (int i = 1; i <= 5; ++i)
            cin >> Elements[i];
        for (int i = 1; i <= 5; ++i)
            cin >> Forces[i];
        cout << "Case:" << __ << endl;
        init(); judge();
    }
    return 0;
}