1. 程式人生 > >第13屆景馳-埃森哲杯廣東工業大學ACM程序設計大賽

第13屆景馳-埃森哲杯廣東工業大學ACM程序設計大賽

規律 == https als body can out pan AC

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程序設計大賽