forked from chr4ss1/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMCOINS.cpp
More file actions
78 lines (58 loc) · 1.53 KB
/
MCOINS.cpp
File metadata and controls
78 lines (58 loc) · 1.53 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
#include <stdio.h>
#include <utility>
#include <string.h>
#include <map>
#include <math.h>
#include <algorithm>
using namespace std;
// this is completely related to I/O and has nothing to do with problem itself.
#define MAX_CHUNK_SIZE 65536
char arr[10000000] = {0};
char *ptr = arr;
// I wrote this custom function in order to get
// better running times in SPOJ.
// This can take your 5 seconds to 1 seconds with big INPUT/OUTPUT :)
void parse_data()
{
//FILE * pFile;
//pFile = fopen ( "C:\\test_case.txt" , "rb" );
int c, j;
char *ptr = arr;
// read data into buffer!
while((c = fread(ptr, 1, MAX_CHUNK_SIZE, stdin))>0)
ptr += MAX_CHUNK_SIZE;
// reset ptr to beginning.
ptr = arr;
}
// A simple inline function that can extract integer from buffer.
inline int extract_int()
{
// skip all stupid whitespaces.
while(*ptr == 13 || *ptr == 10 || *ptr == ' ') ptr++;
int wtf = atoi(ptr);
// skip the integer
while(*ptr >= '0' && *ptr <= '9') ptr++;
return wtf;
}
#define MAX_GAMES 50
#define BIGGEST_TOWER 1000000
int K, L, m;
int towers[MAX_GAMES];
int memo[BIGGEST_TOWER + 1] = {0};//true=WIN,false=LOSE!
int mxx()
{
parse_data();
K = extract_int();
L = extract_int();
m = extract_int();
for(int j = 0; j < m; j++) towers[j] = extract_int();
for(int j = 1; j <= BIGGEST_TOWER; j++){
if(memo[j - 1] == 0) memo[j] = 1;
else if(j - K >= 0 && memo[j - K] == 0) memo[j] = 1;
else if(j - L >= 0 && memo[j - L] == 0) memo[j] = 1;
}
for(int k = 0; k < m; k++){
printf("%c", memo[towers[k]] ? 'A' : 'B');
}
return 0;
}