码迷,mamicode.com
首页 > 其他好文 > 详细

第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛

时间:2018-03-24 20:41:23      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:AC   旋转矩阵   ble   nbsp   大学   bsp   tin   class   埃森哲   

G.旋转矩阵

题解:LR和RL等同没有旋转,所以旋转到最后等价于只向左旋或只向右旋。

感受:fuckkkkk!if-else结构竟然写挂了,比赛结束后真想找块豆腐撞死。

比赛时写的左旋:

 1 /*左旋*/
 2 void print3() {
 3     cout << m << " " << n << endl;
 4     for (int i = m - 1; i >= 0; i--) {
 5         for (int j = 0; j < n; j++) {
 6             if (mp[j][i] == |) mp[j][i] = -;
 7             if (mp[j][i] == -) mp[j][i] = |;    //竟然没找出错误,orzzzzz!
 8             cout << mp[j][i];
 9         }
10         cout << endl;
11     }
12 }

最后AC的代码:

 1 #pragma warning(disable:4996)
 2 #include<cstdio>
 3 #include<string>
 4 #include<cstring>
 5 #include<iostream>
 6 #include<algorithm>
 7 using namespace std;
 8 
 9 const int maxn = 2000;
10 
11 int T, n, m;
12 char mp[100][100];
13 
14 string s;
15 
16 void print1(){
17     cout << n << " " << m << endl;
18     for (int i = 0; i < n; i++) {
19         for (int j = 0; j < m; j++) cout << mp[i][j];
20         cout << endl;
21     }
22 }
23 /*右旋*/
24 void print2() {
25     cout << m << " " << n << endl;
26     for (int i = 0; i < m; i++) {
27         for (int j = n - 1; j >= 0; j--) {
28             if (mp[j][i] == |)  cout << "-";
29             else if (mp[j][i] == -)  cout << "|";
30             else cout << mp[j][i];
31         }
32         cout << endl;
33     }
34 }
35 /*左旋*/
36 void print3() {
37     cout << m << " " << n << endl;
38     for (int i = m - 1; i >= 0; i--) {
39         for (int j = 0; j < n; j++) {
40             if (mp[j][i] == |)  cout << "-";
41             else if (mp[j][i] == -) cout << "|";
42             else cout << mp[j][i];
43         }
44         cout << endl;
45     }
46 }
47 /*左旋两次*/
48 void print4() {
49     cout << n << " " << m << endl;
50     for (int i = n - 1; i >= 0; i--) {
51         for (int j = m - 1; j >= 0; j--) cout << mp[i][j];
52         cout << endl;
53     }
54 }
55 
56 int main()
57 {
58     cin >> T;
59     while (T--) {
60         cin >> n >> m;
61         for (int i = 0; i < n; i++)
62             for (int j = 0; j < m; j++) cin >> mp[i][j];
63         cin >> s;
64 
65         int l = s.size();
66         int p = 0, q = 0;
67         for (int i = 0; i < l; i++) {
68             if (s[i] == L) p++;
69             if (s[i] == R) q++;
70         }
71 
72         if (p == q) print1(); 
73         else if (p > q) {
74             p = (p - q) % 4;
75             if (p == 0) print1(); 
76             else if (p == 1) print3(); 
77             else if (p == 2) print4(); 
78             else print2(); 
79         }
80         else {
81             q = (q - p) % 4;
82             if (q == 0) print1(); 
83             else if (q == 1) print2(); 
84             else if (q == 2) print4(); 
85             else print3();
86         }
87 
88         cout << endl;
89     }
90     return 0;
91 }

J.强迫症序列

题解:每次只能对n-1个数加一,等价于每次只能对1个数减一。而且每个元素都相等的情况只有一种。

 1 #pragma warning(disable:4996)
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7 
 8 const int maxn = 1e5 + 5;
 9 
10 int n;
11 int a[maxn];
12 
13 int main()
14 {    
15     int T;
16     while (cin >> T) {
17         while (T--) {
18             cin >> n;
19             for (int i = 1; i <= n; i++) scanf("%d", a + i);
20             sort(a + 1, a + n + 1);
21             int ans = 0;
22             for (int i = 1; i <= n; i++) ans += (a[i] - a[1]);
23             cout << ans << " " << ans + a[1] << endl;
24         }
25     }
26     return 0;
27 }

K.密码

题解:找规律。

 1 #pragma warning(disable:4996)
 2 #include<cstdio>
 3 #include<string>
 4 #include<cstring>
 5 #include<iostream>
 6 #include<algorithm>
 7 using namespace std;
 8 
 9 const int maxn = 100005;
10 
11 int n, m;
12 char s[maxn];
13 
14 int main()
15 {
16     int T;
17     cin >> T;
18     while (T--) {
19         scanf("%d%s", &n, s);
20         m = strlen(s);
21         if (n == 1 || n >= m) { printf("%s\n", s); continue; }
22 
23         for (int i = 0; i < n; i++) {
24             int t = i;
25             int p = 0;
26             while (t < m) {
27                 cout << s[t];
28                 if (i == 0 || i == n - 1) { t += 2 * (n - 1); continue; }
29                 if (p % 2) t += 2 * i;
30                 else t += 2 * (n - i - 1);
31                 p++;
32             }
33         }
34         cout << endl;
35     }
36     
37     return 0;
38 }

L.用来作弊的药水

题解:分类讨论。

 1 #pragma warning(disable:4996)
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7 
 8 const int maxn = 1e5 + 5;
 9 
10 int n;
11 int a[maxn];
12 
13 int main()
14 {    
15     
16     int T;
17     cin >> T;
18     while (T--) {
19         int x, a, y, b;
20         cin >> x >> a >> y >> b;
21         bool flag = false;
22         while (true) {
23 
24             if (x == 1 && y == 1) { flag = true; break; }
25             if (x == 1 && y != 1) break;
26             if (x != 1 && y == 1) break;
27 
28             if (a == b) {
29                 if (x == y) { flag = true; break; }
30                 else break;
31             }
32             else if (a < b) {
33                 if (x < y || x % y) break;
34                 else {
35                     x = x / y;
36                     b = b - a;
37                 }
38             }
39             else {
40                 if (y < x || y % x) break;
41                 else {
42                     y = y / x;
43                     a = a - b;
44                 }
45             }
46             if (x == y && a != b) break;
47         }
48         if (flag) cout << "Yes" << endl;
49         else cout << "No" << endl;
50         
51     }
52     return 0;
53 }

 

第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛

标签:AC   旋转矩阵   ble   nbsp   大学   bsp   tin   class   埃森哲   

原文地址:https://www.cnblogs.com/zgglj-com/p/8640988.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!