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

A: 模拟26进制加法即可

/*************************************************************************
    > File Name: cf-293-a.cpp
    > Author: ALex
    > Mail: [email protected]
    > 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: [email protected]
    > 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: [email protected]
    > 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: [email protected]
    > 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;
}
时间: 2024-11-05 05:25:50

Codeforces Round #293 (Div. 2)(A, B, C, D)的相关文章

Codeforces Round #293 (Div. 2) D. Ilya and Escalator (概率DP)

dp[i][j]表示第i秒电梯进去的人数为j时的概率.由于概率比较好求,而且这里的样本是有限个.所以可以先求出概率,然后用公式转化成期望. #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <

Codeforces Round #293 (Div. 2)

 A Vitaly and Strings 题意:给定长度相等的字符串s,t,且s的字典序小于t,求一个字符串q字典序大于s小于t. 分析:将字符串看做26进制的数,对s”+1“即可. #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define esp 1e-14 #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #defi

Codeforces Round #293 (Div. 2) D. Ilya and Escalator

先求出概率 设 \(f_{i,j}\) 表示第 \(i\) 秒电梯上有 \(j\) 个人的概率 则 \(f_{0,0}=1\) \(f_{i + 1, j + 1} = f_{i, j} \times p\) \(f_{i + 1, j} = f_{i, j} \times (1 - p)\) \(f_{i+1,n}=f_{i,n}\) 答案即为 \(\sum f_{t, i} \times i\) #include <bits/stdc++.h> #define pb push_back #

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除