我是靠谱客的博主 奋斗小伙,这篇文章主要介绍2015年郑州大学首届“玲珑杯”ACM新生选拔赛题解,现在分享给大家,希望可以做个参考。

C(C++)编译器

判断给定的字符串在不在集合中,用字符串比较函数就行了。
代码:

复制代码
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
/************************************************************************* > File Name: a.cpp > Author: gwq > Mail: gwq5210@qq.com > Created Time: Thu 09 Apr 2015 08:35:46 AM CST ************************************************************************/ #include <cmath> #include <ctime> #include <cctype> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <map> #include <set> #include <queue> #include <stack> #include <string> #include <vector> #include <sstream> #include <iostream> #include <algorithm> #define INF (INT_MAX / 10) #define clr(arr, val) memset(arr, val, sizeof(arr)) #define pb push_back #define sz(a) ((int)(a).size()) using namespace std; typedef set<int> si; typedef vector<int> vi; typedef map<int, int> mii; typedef pair<int, int> pii; typedef long long ll; const double esp = 1e-5; #define N 100010 int cnt = 8; char str[N]; const char *mp[] = {"void", "byte", "char", "int", "long", "float", "double", "__int64"}; int main(int argc, char *argv[]) { while (gets(str) != NULL && strcmp(str, "end") != 0) { int flag = 0; for (int i = 0; i < 8; ++i) { if (strcmp(str, mp[i]) == 0) { flag = 1; break; } } printf("%sn", flag ? "Yes" : "No"); } return 0; }

约瑟夫环

最后一个退出的人是星期几。注意到每个人都要退出,所以将人数取模就行了。

复制代码
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
/************************************************************************* > File Name: b.cpp > Author: gwq > Mail: gwq5210@qq.com > Created Time: Thu 09 Apr 2015 09:07:45 AM CST ************************************************************************/ #include <cmath> #include <ctime> #include <cctype> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <map> #include <set> #include <queue> #include <stack> #include <string> #include <vector> #include <sstream> #include <iostream> #include <algorithm> #define INF (INT_MAX / 10) #define clr(arr, val) memset(arr, val, sizeof(arr)) #define pb push_back #define sz(a) ((int)(a).size()) using namespace std; typedef set<int> si; typedef vector<int> vi; typedef map<int, int> mii; typedef pair<int, int> pii; typedef long long ll; const double esp = 1e-5; const char *mp[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; int main(int argc, char *argv[]) { int n = 0; while (scanf("%d", &n) != EOF && n) { n--; printf("%sn", mp[n % 7]); } return 0; }

QQ

根据给定的规则计算QQ的价值就行了。锻炼代码能力,注意细节就行了。

复制代码
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
/************************************************************************* > File Name: c.cpp > Author: gwq > Mail: gwq5210@qq.com > Created Time: Thu 09 Apr 2015 09:37:11 AM CST ************************************************************************/ #include <cmath> #include <ctime> #include <cctype> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <map> #include <set> #include <queue> #include <stack> #include <string> #include <vector> #include <sstream> #include <iostream> #include <algorithm> #define INF (INT_MAX / 10) #define clr(arr, val) memset(arr, val, sizeof(arr)) #define pb push_back #define sz(a) ((int)(a).size()) using namespace std; typedef set<int> si; typedef vector<int> vi; typedef map<int, int> mii; typedef pair<int, int> pii; typedef long long ll; const double esp = 1e-5; #define N 20 ll d1, d2; char s1[N], s2[N]; ll values(char str[], ll d) { ll ans = d; ll len = strlen(str); for (int i = 0; i < len; ++i) { ans += str[i] - '0'; } int i = 1; int cnt = 1; while (i <= len) { if (str[i] != str[i - 1]) { if (cnt > 1) { ll x = 1; for (int j = 0; j < cnt + 1; ++j) { x *= str[i - 1] - '0' + 1; } ans += x; } cnt = 0; } ++cnt; ++i; } return ans; } int main(int argc, char *argv[]) { while (scanf("%s%lld%s%lld", s1, &d1, s2, &d2) != EOF) { ll l1 = strlen(s1); ll l2 = strlen(s2); ll v1 = values(s1, d1); ll v2 = values(s2, d2); if (l1 < l2) { v1 = 1; v2 = 0; } else if (l1 > l2) { v1 = 0; v2 = 1; } printf("%sn", (v1 > v2) ? "First" : ((v1 < v2) ? "Second" : "Equal")); } return 0; }

行列式

一个类似行列式的东西,主对角线乘积和减去副对角线上的乘积和。注意结果可能爆int。还有2*2和1*1要特判。
有一个技巧就是使用取模,可能是负数的可以加上n。还有一个方法是将二维数组向右边复制一份,但数组要开的足够大。

复制代码
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
#include <cstdio> #define N 15 long long mat[N][N]; int main(void) { int n; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { scanf("%d", &mat[i][j]); } } long long ans = 0; for (int i = 0; i < n; ++i) { int x = 0; int y = i; long long tmp = 1; for (int j = 0; j < n; ++j) { int a = (x + j) % n; int b = (y + j) % n; tmp *= mat[a][b]; } ans += tmp; } for (int i = 0; i < n; ++i) { int x = i; int y = n - 1; long long tmp = 1; for (int j = 0; j < n; ++j) { int a = (x + j + n) % n; int b = (y - j + n) % n; tmp *= mat[a][b]; } ans -= tmp; } if (n == 2) { ans = mat[0][0] * mat[1][1] - mat[1][0] * mat[0][1]; } else if (n == 1) { ans = mat[0][0]; } printf("%lldn", ans); } return 0; }

零比特填充-透明传输

这个题目用的思路和QQ那道题目一样,都是求出来连续相同的字符个数,这个要求去掉连续5个1后的零,遇到这个跳过这个字符就行了。

复制代码
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
#include <cstdio> #include <cstring> #define N 1010 int len; char str[N], tmp[N]; void check(void) { int cnt = 1; int flag = 1; for (int i = 1; i <= len; ++i) { if (str[i] != str[i - 1]) { if (str[i - 1] == '1') { if (cnt > 5) { flag = 0; strcpy(str, "Bad luck!"); break; } } cnt = 0; } ++cnt; } if (flag) { cnt = 1; strcpy(tmp, str); int x = 0; for (int i = 1; i <= len; ++i) { str[x++] = tmp[i - 1]; if (tmp[i] != tmp[i - 1]) { if (tmp[i - 1] == '1' && cnt == 5) { ++i; } cnt = 0; } ++cnt; } str[x] = ''; } } int main(void) { while (scanf("%d%s", &len, str) != EOF) { check(); printf("%sn", str); } return 0; }

数字游戏

求出来逆序过来的数就行了,然后根据题目描述模拟一下,要记录中间的结果。

复制代码
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
/************************************************************************* > File Name: e.cpp > Author: gwq > Mail: gwq5210@qq.com > Created Time: Thu 09 Apr 2015 10:54:26 AM CST ************************************************************************/ #include <cmath> #include <ctime> #include <cctype> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <map> #include <set> #include <queue> #include <stack> #include <string> #include <vector> #include <sstream> #include <iostream> #include <algorithm> #define INF (INT_MAX / 10) #define clr(arr, val) memset(arr, val, sizeof(arr)) #define pb push_back #define sz(a) ((int)(a).size()) using namespace std; typedef set<int> si; typedef vector<int> vi; typedef map<int, int> mii; typedef pair<int, int> pii; typedef long long ll; const double esp = 1e-5; #define N 1000010 int num[N]; int rev(int n) { int ans = 0; while (n) { ans = ans * 10 + n % 10; n /= 10; } return ans; } int main(int argc, char *argv[]) { int n; while (scanf("%d", &n) != EOF) { int cnt = 0; while (n != rev(n)) { num[cnt] = n; n = n + rev(n); ++cnt; } num[cnt++] = n; printf("%dn", cnt - 1); for (int i = 0; i < cnt; ++i) { if (i > 0) { printf("--->"); } printf("%d", num[i]); } printf("n"); } return 0; }

简单求值

求表达式的值,是数据结构中栈的基本应用。不过这个可以不用栈,因为没有括号,可以从左到右找到第一个*或者/号,计算,替换,一直重复就行了,最后,再计算+或-就行了。下面是栈的版本,用了一个特殊符号,用来表示结束,来计算最后优先级都相同的情况,还有栈为空的特殊情况。

复制代码
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 <cstdio> #include <cctype> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 1010 char op[N], str[N]; int num[N], op_top, num_top; // 这个用来比较运算符的优先级 int opcmp(char c1, char c2) { if (op_top == 0) { return -1; } char mp[] = "$ +- */ ^"; int idx1 = 0; int idx2 = 0; for (int i = 0; i < strlen(mp); ++i) { if (mp[i] == c1) { idx1 = i; } if (mp[i] == c2) { idx2 = i; } } if (abs(idx1 - idx2) <= 1) { return 0; } else { return idx1 - idx2; } } int main(void) { while (scanf("%s", str) != EOF) { int len = strlen(str); int m = 0; op_top = 0; num_top = 0; str[len] = '$'; str[len + 1] = ''; for (int i = 0; i <= len; ++i) { if (isdigit(str[i])) { m = 10 * m + str[i] - '0'; } else { num[num_top++] = m; //printf("%d.%c.%c.n", m, op[op_top - 1], str[i]); m = 0; while (opcmp(op[op_top - 1], str[i]) >= 0) { char x = op[--op_top]; int n1 = num[--num_top]; int n2 = num[--num_top]; int ans = 0; //printf("%d %c %dn", n2, x, n1); switch (x) { case '+': ans = n2 + n1; break; case '*': ans = n2 * n1; break; case '-': ans = n2 - n1; break; case '/': ans = n2 / n1; break; } num[num_top++] = ans; } op[op_top++] = str[i]; } } printf("%dn", num[num_top - 1]); } return 0; }

最后

以上就是奋斗小伙最近收集整理的关于2015年郑州大学首届“玲珑杯”ACM新生选拔赛题解的全部内容,更多相关2015年郑州大学首届“玲珑杯”ACM新生选拔赛题解内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(91)

评论列表共有 0 条评论

立即
投稿
返回
顶部