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

C.平分遊戲node

D.psd面試ios

感覺:dp仍是不會,雖然這是最簡單的dp。。。。。面試

 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 = 1500; 10 
11 int n, dp[maxn][maxn]; 12 string s; 13 
14 void LPS() { 15     memset(dp, 0, sizeof(dp)); 16     for (int i = 0; i < n; i++) dp[i][i] = 1; 17     for (int i = 1; i < n; i++) { 18         int tp = 0; 19         for (int j = 0; j + i < n; j++) { 20             if (s[j] == s[j + i]) tp = dp[j + 1][j + i - 1] + 2; 21             else tp = max(dp[j + 1][j + i], dp[j][j + i - 1]); 22             dp[j][j + i] = tp; 23  } 24  } 25     cout << n - dp[0][n - 1] << endl; 26 } 27 
28 int main() 29 { 30     while (cin >> s) { 31         n = s.size(); 32         for (int i = 0; i < n; i++) if (s[i] >= 'A'&& s[i] <= 'Z') s[i] = tolower(s[i]); 33  LPS(); 34  } 35     return 0; 36 }

E.迴旋星空url

題解:枚舉中間的那個點,分別計算其它點到這個點的距離,再排序。那麼相同距離的就會排在一塊兒。spa

感覺:想到了枚舉中間點,但算錯了複雜度。。。。.net

 1 #pragma warning(disable:4996)
 2 #include<map>
 3 #include<vector>
 4 #include<stack>
 5 #include<queue>
 6 #include<cstdio>
 7 #include<string>
 8 #include<cstring>
 9 #include<iostream>
10 #include<algorithm>
11 using namespace std; 12 typedef long long ll; 13 
14 const int maxn = 1005; 15 
16 int n, T; 17 
18 struct node { 19     int x, y; 20 }p[maxn]; 21 
22 /*struct mode { 23     int s, e, d; 24     bool operator<(const mode& i)const { 25         return d < i.d; 26  } 27 }q[maxn];*/ 28 
29 inline int cad(node a, node b) { return (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y); } 30 
31 int main() 32 { 33     cin >> T; 34     while (T--) { 35         cin >> n; 36         for (int i = 1; i <= n; i++) cin >> p[i].x >> p[i].y; 37 
38         ll ans = 0; 39         for (int i = 1; i <= n; i++) { 40             vector<int> d; 41             for (int j = 1; j <= n; j++) if (j != i)d.push_back(cad(p[i], p[j])); 42  sort(d.begin(), d.end()); 43             
44             int cnt = 1; 45             for (int j = 1; j < d.size(); j++) { 46                 if (d[j] == d[j - 1]) cnt++; 47                 else { 48                     ans += cnt * (cnt - 1); 49                     cnt = 1; 50  } 51  } 52             ans += cnt * (cnt - 1); 53  } 54         if (ans == 0) cout << "WA" << endl; 55         else printf("%lld\n", ans); 56             
57  } 58     return 0; 59 }

F.等式code

題解:假設x=n+a,y=n+b;代入方程得:n*n=a*b。因此若是n*n有p個因子,則ans=(p+1)/2;由於n*n的質因子和n的質因子是相同的,因此這裏分解n就好了。blog

感覺:網上的大佬就是6啊!不過這題是原題,poj2917。排序

 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 int n, T; 10 int num[64]; 11 
12 int main() 13 { 14     cin >> T; 15     while (T--) { 16         cin >> n; 17         memset(num, 0, sizeof(num)); 18         int p = 0; 19         for (int i = 2; i*i <= n; i++) { 20             if (n % i) continue; 21             while (n % i == 0) { 22                 num[p]++; 23                 n /= i; 24  } 25             p++; 26  } 27         if (n != 1) { 28             num[p]++; 29             p++; 30  } 31         for (int i = 0; i < p; i++) num[i] *= 2; 32         int ans = 1; 33         for (int i = 0; i < p; i++) ans *= (num[i] + 1); 34         cout << (ans+1)/2 << endl; 35  } 36     return 0; 37 }

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 }
相關文章
相關標籤/搜索