zoukankan      html  css  js  c++  java
  • 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛

    C.平分游戏

    D.psd面试

    感受: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.回旋星空

    题解:枚举中间的那个点,分别计算其它点到这个点的距离,再排序。那么相同距离的就会排在一起。

    感受:想到了枚举中间点,但算错了复杂度。。。。

     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
    ", ans);
    56             
    57     }
    58     return 0;
    59 }

    F.等式

    题解:假设x=n+a,y=n+b;代入方程得:n*n=a*b。所以如果n*n有p个因子,则ans=(p+1)/2;因为n*n的质因子和n的质因子是相同的,所以这里分解n就行了。

    感受:网上的大佬就是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
    ", 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 }
  • 相关阅读:
    FJNU 1151 Fat Brother And Geometry(胖哥与几何)
    FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术)
    FJNU 1159 Fat Brother’s new way(胖哥的新姿势)
    HDU 3549 Flow Problem(最大流)
    HDU 1005 Number Sequence(数列)
    Tickets(基础DP)
    免费馅饼(基础DP)
    Super Jumping! Jumping! Jumping!(基础DP)
    Ignatius and the Princess IV(基础DP)
    Keywords Search(AC自动机)
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/8640988.html
Copyright © 2011-2022 走看看