zoukankan      html  css  js  c++  java
  • * Credenz 2014 Wild Card Round题解

    A题

    简单模拟。

     1 /*************************************************************************
     2     > File Name: A.cpp
     3     > Author: Stomach_ache
     4     > Mail: sudaweitong@gmail.com
     5     > Created Time: 2014年09月01日 星期一 08时08分12秒
     6     > Propose: 
     7  ************************************************************************/
     8 
     9 #include <cmath>
    10 #include <string>
    11 #include <cstdio>
    12 #include <string>
    13 #include <fstream>
    14 #include <cstring>
    15 #include <iostream>
    16 #include <algorithm>
    17 using namespace std;
    18 /*Let's fight!!!*/
    19 
    20 int n;
    21 string s;
    22 double a, f;
    23 
    24 int main(void) {
    25       while (cin >> n) {
    26         cin >> s;
    27         cin >> a >> f;
    28 
    29         double sum = 0.0;
    30         int m = (int)s.length();
    31         bool flag = true;
    32         for (int i = 0; i < m; i++) {
    33             if (s[i] == 'L') sum -= a;
    34             else sum += a;
    35             if (sum >= f || sum <= -f) {flag = false; break;}
    36         }
    37         printf("%s
    ", flag ? "YES" : "NO");
    38     }
    39 
    40     return 0;
    41 }

    B题

    判断最大值和剩下的值的和的关系

     1 /*************************************************************************
     2     > File Name: B.cpp
     3     > Author: Stomach_ache
     4     > Mail: sudaweitong@gmail.com
     5     > Created Time: 2014年09月01日 星期一 14时26分17秒
     6     > Propose: 
     7  ************************************************************************/
     8 
     9 #include <cmath>
    10 #include <string>
    11 #include <cstdio>
    12 #include <fstream>
    13 #include <cstring>
    14 #include <iostream>
    15 #include <algorithm>
    16 using namespace std;
    17 /*Let's fight!!!*/
    18 
    19 int n, m;
    20 
    21 int main(void) {
    22     ios::sync_with_stdio(false);
    23     while (cin >> m >> n) {
    24         long long sum = 0, t = -1, a;
    25         for (int i = 0; i < m; i++) cin >> a, t = max(t, a), sum += a;
    26         sum -= t;
    27         if (t > sum + 1) cout << "NO
    ";
    28         else cout << "YES
    ";
    29     }
    30     return 0;
    31 }

    C题

    模拟。

     1 /*************************************************************************
     2     > File Name: C.cpp
     3     > Author: Stomach_ache
     4     > Mail: sudaweitong@gmail.com
     5     > Created Time: 2014年09月01日 星期一 14时32分40秒
     6     > Propose: 
     7  ************************************************************************/
     8 #include <map>
     9 #include <cmath>
    10 #include <string>
    11 #include <vector>
    12 #include <cstdio>
    13 #include <fstream>
    14 #include <cstring>
    15 #include <iostream>
    16 #include <algorithm>
    17 using namespace std;
    18 /*Let's fight!!!*/
    19 
    20 int vis[100050];
    21 
    22 int main(void) {
    23       ios::sync_with_stdio(false);
    24       int n;
    25       while (cin >> n) {
    26         map<string, int> var;
    27         vector<string> s(n + 1);
    28         for (int i = 1; i <= n; i++) cin >> s[i];
    29         memset(vis, 0, sizeof(vis));
    30 
    31         for (int i = 1; i <= n; i++) {
    32             if (var.find(s[i]) == var.end()) var[s[i]] = 1;
    33             else var[s[i]]++;
    34             if (!vis[var[s[i]]]) vis[var[s[i]]] = i;
    35         }
    36         for (int i = 1; i <= n && vis[i]; i++) cout << i << ' ' << s[vis[i]] << endl;
    37     }
    38 
    39     return 0;
    40 }

    D题

    从后往前计算,判断当前点在左上或者右上或者左下或者右下,然后分别乘以不同的系数,并且更新点的位置。

     1 /*************************************************************************
     2     > File Name: D.cpp
     3     > Author: Stomach_ache
     4     > Mail: sudaweitong@gmail.com
     5     > Created Time: 2014年09月01日 星期一 14时56分31秒
     6     > Propose: 
     7  ************************************************************************/
     8 
     9 #include <cmath>
    10 #include <string>
    11 #include <cstdio>
    12 #include <fstream>
    13 #include <cstring>
    14 #include <iostream>
    15 #include <algorithm>
    16 using namespace std;
    17 /*Let's fight!!!*/
    18 
    19 int t, a, b, c, d, x, y;
    20 typedef long long LL;
    21 
    22 int main(void) {
    23       ios::sync_with_stdio(false);
    24     cin >> t;
    25     while (t--) {
    26           int n;
    27           cin >> n;
    28         cin >> a >> b >> c >> d;
    29         cin >> x >> y;
    30 
    31         int times = 0;
    32         while ((1<<times) < max(x, y)) times++;
    33         LL ans = 1;
    34         while (times--) {
    35             if (x <= (1<<times)) {
    36                   if (y <= (1<<times)) ans *= a;
    37                 else ans *= b, y -= 1<<times;
    38             } else {
    39                   x -= 1<<times;
    40                   if (y <= (1<<times)) ans *= c;
    41                 else ans *= d, y -= 1<<times;
    42             }
    43         }
    44         cout << ans << endl;
    45     }
    46 
    47     return 0;
    48 }

    E题

    比赛时候没有过。可以先枚举角度(从0到2*pi,每次加1e-7,加多了就会WA),求得系数。

     1 /*************************************************************************
     2     > File Name: E.cpp
     3     > Author: Stomach_ache
     4     > Mail: sudaweitong@gmail.com
     5     > Created Time: 2014年09月01日 星期一 15时34分16秒
     6     > Propose: 
     7  ************************************************************************/
     8 
     9 #include <cmath>
    10 #include <string>
    11 #include <cstdio>
    12 #include <fstream>
    13 #include <cstring>
    14 #include <iostream>
    15 #include <algorithm>
    16 using namespace std;
    17 /*Let's fight!!!*/
    18 
    19 int main(void) {
    20       /*double ans;
    21     ans=0.0;
    22     double pi = acos(-1.0);
    23     for (double i = 0.0; i < 2 * pi; i += 0.0000001)
    24     {
    25       ans += sqrt(5.0 - 4.0 * cos(i));
    26     }
    27     ans /= 2 * pi * 10000000;
    28     cout << ans << endl; */
    29     int r;
    30     while (cin >> r) cout << (int)(r * 2.12709) <<endl;
    31     return 0;
    32 }

    F题

    因为y-x < 1e4,以此作为着手点。先去掉Ai中大于y-x+1的系数,然后去重。

    之后就转化为完全背包。

     1 /*************************************************************************
     2     > File Name: F.cpp
     3     > Author: Stomach_ache
     4     > Mail: sudaweitong@gmail.com
     5     > Created Time: 2014年09月01日 星期一 19时14分48秒
     6     > Propose: 
     7  ************************************************************************/
     8 #include <set>
     9 #include <cmath>
    10 #include <string>
    11 #include <cstdio>
    12 #include <fstream>
    13 #include <vector>
    14 #include <cstring>
    15 #include <iostream>
    16 #include <algorithm>
    17 using namespace std;
    18 /*Let's fight!!!*/
    19 
    20 int n, x, y, dp[10005];
    21 
    22 int main(void) {
    23     ios::sync_with_stdio(false);
    24     while (cin >> n) {
    25         cin >> x >> y;
    26         int cnt = 0;
    27         vector<int> a;
    28         for (int i = 1; i <= n; i++) {
    29             int tmp;
    30             cin >> tmp;
    31             if (tmp <= y - x + 1) a.push_back(tmp - 1);
    32         }
    33         sort(a.begin(), a.end());
    34         a.erase(unique(a.begin(), a.end()), a.end());
    35         cnt = a.size();
    36         memset(dp, 0x3f, sizeof(dp));
    37         int V = y - x;
    38         dp[0] = 0;
    39         for (int i = 0; i < cnt; i++) {
    40             for (int j = a[i]; j <= V; j++) {
    41                   if (dp[j - a[i]] != 0x3f3f3f3f) dp[j] = min(dp[j], dp[j - a[i]] + a[i]);
    42             }
    43         }
    44         if (dp[V] == 0x3f3f3f3f) puts("IMPOSSIBLE");
    45         else puts("POSSIBLE");
    46 
    47     }
    48 
    49     return 0;
    50 }

     H题

    给n个不大于1e9的数,要求找出2个数使得这两个数进行没有进位的加法的结果最大。

    思路:用Trie树维护每一个数,初始时树为空,没输入一个数,先在树中找某个数与之进行无进位加法可以得到的最大值,

    更新最大值,然后将该数加进树中。

    下面就是如何找到与某个数进行加法可以得到的最大值,从高位枚举到低位,肯定优先满足最高位最大,这样才能使得结果最大,

    对于每一位,降序枚举进行加法可以得到的和,就是9到0,看能否满足,如果满足就跳出并判断下一位,并更新结果。

    Accepted Code:

     1 /*************************************************************************
     2     > File Name: H.cpp
     3     > Author: Stomach_ache
     4     > Mail: sudaweitong@gmail.com
     5     > Created Time: 2014年09月02日 星期二 20时27分32秒
     6     > Propose: 
     7  ************************************************************************/
     8 #include <cmath>
     9 #include <string>
    10 #include <cstdio>
    11 #include <fstream>
    12 #include <cstring>
    13 #include <iostream>
    14 #include <algorithm>
    15 using namespace std;
    16 /*Let's fight!!!*/
    17 
    18 #define rep(i, n) for (int i = (0); i < (n); i++)
    19 #define per(i, n) for (int i = (n); i > 0; i--)
    20 #define FOR(i, n) for (int i = (1); i <= (n); i++)
    21 #define ROF(i, n) for (int i = (n); i >= (1); i--)
    22 const int MAX_N = 1000050;
    23 int ch[MAX_N][12], p[12];
    24 struct Trie {
    25     int sz;
    26     Trie() {
    27         memset(ch[0], -1, sizeof(ch[0]));
    28         sz = 1;
    29     }
    30     void insert(int num) {
    31         int u = 0;
    32         for (int i = 8; i >= 0; i--) {
    33             int id = num / p[i];
    34             if (id >= 10) id %= 10;
    35             if (ch[u][id] == -1) {
    36                 memset(ch[sz], -1, sizeof(ch[sz]));
    37                 ch[u][id] = sz++;
    38             }
    39             u = ch[u][id];
    40         }
    41     }
    42     int find_max(int num) {
    43         int u = 0, ans = 0;
    44         for (int i = 8; i >= 0; i--) {
    45             int id = num / p[i];
    46             if (id >= 10) id %= 10;
    47             for (int j = 9; j >= 0; j--) {
    48                 int tmp = j - id;
    49                 tmp = (tmp + 10) % 10;
    50                 if (ch[u][tmp] != -1) {
    51                     ans += p[i] * j;
    52                     u = ch[u][tmp];
    53                     break;
    54                 }
    55             }
    56         }
    57         return ans;
    58     }
    59 };
    60 
    61 int main(void) {
    62     ios_base::sync_with_stdio(false);
    63     p[0] = 1;
    64     FOR (i, 9) p[i] = p[i - 1] * 10;
    65     int n;
    66     while (cin >> n) {
    67           Trie A;
    68           int ans = -1, num;
    69           rep (i, n) {
    70             cin >> num;
    71             if (i != 0) ans = max(ans, A.find_max(num));
    72             A.insert(num);
    73         }
    74         cout << ans << endl;
    75     }
    76 
    77     return 0;
    78 }
  • 相关阅读:
    【Android】升级ADT 22 引发的错误
    【Android】使用SearchView时软键盘不支持actionSearch的问题
    Mac 升级 OS X 10.8.2 后 VirtualBox 无法启动的问题
    2012年总结
    【Andorid X 项目笔记】魅族照片剪切问题(4)
    【读书笔记】浪潮之巅
    ormlite更改数据库默认位置
    Android实用代码七段(二)
    Android实用代码七段(三)
    【Android】嵌套Fragment无法接收onCreateOptionsMenu事件的问题
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/3952089.html
Copyright © 2011-2022 走看看