google code jam Qualification Round 2012
朴素的方法水过三题
1
/**/
/*
2google code jam
3Qualification Round 2012
4Problem a
5*/
6 #include < stdio.h >
7
8 #define LM 128
9 #define LS 109
10
11 char unmap[ LM ];
12 char words[ LS ];
13
14 void init() {
15 int i;
16 char *normal = "our language is impossible to understand there are twenty six factorial possibilities so it is okay if you want to just give up";
17 char *google = "ejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd de kr kd eoya kw aej tysr re ujdr lkgc jv";
18 for ( i = 0; i < LM; ++i ) {
19 unmap[ i ] = i;
20 }
21 unmap[ 'y' ] = 'a';
22 unmap[ 'e' ] = 'o';
23 unmap[ 'q' ] = 'z';
24 while ( (*normal) && (*google) ) {
25 unmap[ *google++ ] = *normal++;
26 }
27 unmap[ 'z' ] = 'q';
28}
29
30 int main() {
31 int tc, cc;
32 char *p;
33
34 init();
35
36 scanf("%d", &tc);
37 gets(words);
38 for ( cc = 1; cc <= tc; ++cc ) {
39 gets(words);
40 for ( p = words; *p; ++p ) {
41 *p = unmap[ *p ];
42 }
43 printf("Case #%d: %s\n", cc, words);
44 }
45 return 0;
46}
47
2google code jam
3Qualification Round 2012
4Problem a
5*/
6 #include < stdio.h >
7
8 #define LM 128
9 #define LS 109
10
11 char unmap[ LM ];
12 char words[ LS ];
13
14 void init() {
15 int i;
16 char *normal = "our language is impossible to understand there are twenty six factorial possibilities so it is okay if you want to just give up";
17 char *google = "ejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd de kr kd eoya kw aej tysr re ujdr lkgc jv";
18 for ( i = 0; i < LM; ++i ) {
19 unmap[ i ] = i;
20 }
21 unmap[ 'y' ] = 'a';
22 unmap[ 'e' ] = 'o';
23 unmap[ 'q' ] = 'z';
24 while ( (*normal) && (*google) ) {
25 unmap[ *google++ ] = *normal++;
26 }
27 unmap[ 'z' ] = 'q';
28}
29
30 int main() {
31 int tc, cc;
32 char *p;
33
34 init();
35
36 scanf("%d", &tc);
37 gets(words);
38 for ( cc = 1; cc <= tc; ++cc ) {
39 gets(words);
40 for ( p = words; *p; ++p ) {
41 *p = unmap[ *p ];
42 }
43 printf("Case #%d: %s\n", cc, words);
44 }
45 return 0;
46}
47
1
/**/
/*
2google code jam
3Qualification Round 2012
4Problem b
5*/
6
7 #include < stdio.h >
8
9 #define MIN(x, y) (((x)<(y)) ? (x) : (y))
10 #define MAX(x, y) (((x)>(y)) ? (x) : (y))
11
12 int main() {
13 int tc, cc;
14 int n, s, p, t;
15 int i;
16 int ans, ans_sns, ans_s, ans_ns, res;
17 scanf("%d", &tc);
18 for ( cc = 1; cc <= tc; ++cc ) {
19 ans_sns = ans_s = ans_ns = 0;
20 scanf("%d%d%d", &n, &s, &p);
21 for ( i = 0; i < n; ++i ) {
22 scanf("%d", &t);
23 switch( t % 3 ) {
24 case 0 :
25 res = t / 3;
26 if ( 3 > t ) {
27 if ( res >= p ) {
28 ++ans_ns;
29 }
30 }
31 else {
32 if ( res >= p ) {
33 ++ans_sns;
34 }
35 else if ( res + 1 >= p ) {
36 ++ans_s;
37 }
38 }
39 break;
40 case 1 :
41 res = t / 3 + 1;
42 if ( 3 > t ) {
43 if ( res >= p ) {
44 ++ans_ns;
45 }
46 }
47 else {
48 if ( res >= p ) {
49 ++ans_sns;
50 }
51 }
52 break;
53 case 2 :
54 res = t / 3 + 1;
55 if ( res >= p ) {
56 ++ans_sns;
57 }
58 else if ( res + 1 >= p ) {
59 ++ans_s;
60 }
61 break;
62 }
63 }
64
65 ans = ans_ns + MIN(ans_s, s) + ans_sns;
66 printf("Case #%d: %d\n", cc, ans);
67 }
68 return 0;
69}
70
2google code jam
3Qualification Round 2012
4Problem b
5*/
6
7 #include < stdio.h >
8
9 #define MIN(x, y) (((x)<(y)) ? (x) : (y))
10 #define MAX(x, y) (((x)>(y)) ? (x) : (y))
11
12 int main() {
13 int tc, cc;
14 int n, s, p, t;
15 int i;
16 int ans, ans_sns, ans_s, ans_ns, res;
17 scanf("%d", &tc);
18 for ( cc = 1; cc <= tc; ++cc ) {
19 ans_sns = ans_s = ans_ns = 0;
20 scanf("%d%d%d", &n, &s, &p);
21 for ( i = 0; i < n; ++i ) {
22 scanf("%d", &t);
23 switch( t % 3 ) {
24 case 0 :
25 res = t / 3;
26 if ( 3 > t ) {
27 if ( res >= p ) {
28 ++ans_ns;
29 }
30 }
31 else {
32 if ( res >= p ) {
33 ++ans_sns;
34 }
35 else if ( res + 1 >= p ) {
36 ++ans_s;
37 }
38 }
39 break;
40 case 1 :
41 res = t / 3 + 1;
42 if ( 3 > t ) {
43 if ( res >= p ) {
44 ++ans_ns;
45 }
46 }
47 else {
48 if ( res >= p ) {
49 ++ans_sns;
50 }
51 }
52 break;
53 case 2 :
54 res = t / 3 + 1;
55 if ( res >= p ) {
56 ++ans_sns;
57 }
58 else if ( res + 1 >= p ) {
59 ++ans_s;
60 }
61 break;
62 }
63 }
64
65 ans = ans_ns + MIN(ans_s, s) + ans_sns;
66 printf("Case #%d: %d\n", cc, ans);
67 }
68 return 0;
69}
70
1
/**/
/*
2google code jam
3Qualification Round 2012
4Problem c
5*/
6
7 #include < stdio.h >
8 #include < string .h >
9 #include < stdlib.h >
10
11 #define L 2000009
12
13 void shift( char * str, int len) {
14 int i;
15 char tmp = str[ 0 ];
16 for ( i = 1; i < len; ++i ) {
17 str[ i-1 ] = str[ i ];
18 }
19 str[ len-1 ] = tmp;
20}
21
22 int solve( int a, int b) {
23 static char used[ L ];
24 char num[ 64 ];
25 int i, j, k, len, cnt, ans = 0;
26
27 memset(used, 0, sizeof(used));
28 for ( i = a; i <= b; ++i ) {
29 if ( used[ i ] ) {
30 continue;
31 }
32
33 itoa(i, num, 10);
34 len = strlen(num);
35 cnt = 0;
36
37 for ( j = 0; j < len; ++j ) {
38 k = atoi(num);
39 if ( ('0' != num[0]) && (a <= k) && (k <= b) && (! used[k]) ) {
40 ++cnt;
41 used[ k ] = 1;
42 }
43 shift(num, len);
44 }
45
46 ans += cnt * (cnt - 1) / 2;
47 }
48
49 return ans;
50}
51
52 int main() {
53 int tc, cc;
54 int a, b;
55 scanf("%d", &tc);
56 for ( cc = 1; cc <= tc; ++cc ) {
57 scanf("%d%d", &a, &b);
58 printf("Case #%d: %d\n", cc, solve(a, b));
59 }
60 return 0;
61}
62
2google code jam
3Qualification Round 2012
4Problem c
5*/
6
7 #include < stdio.h >
8 #include < string .h >
9 #include < stdlib.h >
10
11 #define L 2000009
12
13 void shift( char * str, int len) {
14 int i;
15 char tmp = str[ 0 ];
16 for ( i = 1; i < len; ++i ) {
17 str[ i-1 ] = str[ i ];
18 }
19 str[ len-1 ] = tmp;
20}
21
22 int solve( int a, int b) {
23 static char used[ L ];
24 char num[ 64 ];
25 int i, j, k, len, cnt, ans = 0;
26
27 memset(used, 0, sizeof(used));
28 for ( i = a; i <= b; ++i ) {
29 if ( used[ i ] ) {
30 continue;
31 }
32
33 itoa(i, num, 10);
34 len = strlen(num);
35 cnt = 0;
36
37 for ( j = 0; j < len; ++j ) {
38 k = atoi(num);
39 if ( ('0' != num[0]) && (a <= k) && (k <= b) && (! used[k]) ) {
40 ++cnt;
41 used[ k ] = 1;
42 }
43 shift(num, len);
44 }
45
46 ans += cnt * (cnt - 1) / 2;
47 }
48
49 return ans;
50}
51
52 int main() {
53 int tc, cc;
54 int a, b;
55 scanf("%d", &tc);
56 for ( cc = 1; cc <= tc; ++cc ) {
57 scanf("%d%d", &a, &b);
58 printf("Case #%d: %d\n", cc, solve(a, b));
59 }
60 return 0;
61}
62