Codeforces Round #293 (Div. 2)(A, B, C, D),

來源:互聯網
上載者:User

Codeforces Round #293 (Div. 2)(A, B, C, D),

A: 類比26進位加法即可

/*************************************************************************    > File Name: cf-293-a.cpp    > Author: ALex    > Mail: zchao1995@gmail.com     > Created Time: 2015年02月25日 星期三 13時40分05秒 ************************************************************************/#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const double pi = acos(-1);const int inf = 0x3f3f3f3f;const double eps = 1e-15;typedef long long LL;typedef pair <int, int> PLL;string A, B;int main (){    while (cin >> A >> B)    {        int len = A.length();        int c = 1;        for (int i = len - 1; i >= 0; --i)        {            if (!c)            {                break;            }            if (A[i] == 'z' && c)            {                A[i] = 'a';            }            else if (c)            {                ++A[i];                c = 0;            }        }        if (A >= B)        {            cout << "No such string" << endl;            continue;        }        cout << A << endl;    }    return 0;}

B:注意讀題仔細,另外要先計算第一個答案,標記好,再去算第二個答案

/*************************************************************************    > File Name: cf-293-b.cpp    > Author: ALex    > Mail: zchao1995@gmail.com     > Created Time: 2015年02月25日 星期三 01時01分17秒 ************************************************************************/#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const double pi = acos(-1);const int inf = 0x3f3f3f3f;const double eps = 1e-15;typedef long long LL;typedef pair <int, int> PLL;const int N = 200100;char s[N], t[N];bool vis[N];int num[130];int main (){    while (~scanf("%s%s", s, t))    {        int ans1 = 0, ans2 = 0;        int len = strlen (t);        memset (num, 0, sizeof(num));        memset (vis, 0, sizeof(vis));        for (int i = 0; i < len; ++i)        {            ++num[t[i]];        }        len = strlen (s);        for (int i = 0; i < len; ++i)        {            if (num[s[i]] > 0)            {                vis[i] = 1;                ++ans1;                --num[s[i]];            }        }        for (int i = 0; i < len; ++i)        {            if (!vis[i])            {                if (s[i] >= 'A' && s[i] <= 'Z')                {                    if (num[s[i] - 'A' + 'a'] > 0)                    {                        ++ans2;                        --num[s[i] - 'A' + 'a'];                    }                }                else                {                    if (num[s[i] - 'a' + 'A'] > 0)                    {                        ++ans2;                        --num[s[i] - 'a' + 'A'];                    }                }            }        }        printf("%d %d\n", ans1, ans2);    }    return 0;}

C:水題類比題

/*************************************************************************    > File Name: cf-293-c.cpp    > Author: ALex    > Mail: zchao1995@gmail.com     > Created Time: 2015年02月25日 星期三 14時36分58秒 ************************************************************************/#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const double pi = acos(-1);const int inf = 0x3f3f3f3f;const double eps = 1e-15;typedef long long LL;typedef pair <int, int> PLL;const int N = 100100;vector <int> scr[N];int arr[N];int at[N];int ord[N];int main (){    int n, m, k;    int app;    while (~scanf("%d%d%d", &n, &m, &k))    {        for (int i = 1; i <= n; ++i)        {            scr[i].clear();        }        for (int i = 1; i <= n; ++i)        {            int pos = i / k + ((i % k) ? 1 : 0);            scanf("%d", &app);            at[app] = pos;            scr[pos].push_back (app);            if (i % k)            {                ord[app] = i % k - 1;            }            else            {                ord[app] = k - 1;            }        }        LL ans = 0;        for (int i = 1; i <= m; ++i)        {            scanf("%d", &app);            ans += at[app];            int s = at[app];            int cur = ord[app];            if (s == 1 && cur == 0)            {                continue;            }            if (cur == 0)            {                int size = scr[s - 1].size();                int &a = scr[s - 1][size - 1];                int &b = scr[s][cur];                at[a] = s;                at[b] = s - 1;                ord[a] = 0;                ord[b] = size - 1;                swap (a, b);            }            else            {                int &a = scr[s][cur - 1];                int &b = scr[s][cur];                ord[a] = cur;                ord[b] = cur - 1;                swap (a, b);            }        }        printf("%I64d\n", ans);}

D:水題機率dp
設dp[i][j] i秒時,車廂裡j個人的機率

/*************************************************************************    > File Name: cf-293-d.cpp    > Author: ALex    > Mail: zchao1995@gmail.com     > Created Time: 2015年02月25日 星期三 01時59分30秒 ************************************************************************/#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const double pi = acos(-1);const int inf = 0x3f3f3f3f;const double eps = 1e-15;typedef long long LL;typedef pair <int, int> PLL;double dp[2010][2010];int n, t;double p;int main (){    while (~scanf("%d%lf%d", &n, &p, &t))    {        memset (dp, 0, sizeof(dp));        dp[0][0] = 1;        for (int i = 1; i <= t; ++i)        {            dp[i][0] = dp[i - 1][0] * (1 - p);            int e = min (n, i);            for (int j = 1; j <= e; ++j)            {                if (j < e)                {                    dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j] * (1 - p);                }                else                {                    dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j];                }            }        }        double ans = 0;        for (int i = 0; i <= t; ++i)        {            ans += dp[t][i] * i;        }        printf("%.10f\n", ans);    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.