Codeforces Round #689 (Div. 2, based on Zed Code Competition) A-C

A. String Generation
水题,先输出m个a后在由c’b,a的顺序倒序输出即可。

#include<bits/stdc++.h>
using namespace std;
#define IO() ios::sync_with_stdio(false);\
             cin.tie(NULL);\
             cout.tie(NULL);
#define MULTICASE int _;cin >> _;while(_ --)
main(){
    IO();
    MULTICASE
    {
        int n, m;
        cin >> n >> m;
        cout << string(m, 'a');
 
        char c = 'c';
        for(int i = m + 1;i <= n;i ++)
        {
            cout << c ;
            c = (c - 1);
            if(c < 'a')c = 'c';
        }
 
        cout << endl;
    }
}

B. Find the Spruce
这道题我简单的方法没想到,想到一个 O ( n 3 ) O(n^3) O(n3)的解法,大概要计算 50 0 3 = 1.25 ∗ 1 0 8 500^3=1.25*10^8 5003=1.25108
对于每一行的输入,我们给连续的一段’*'染上相同的颜色,如下图
在这里插入图片描述
我们可以看到,一个合格的“spruce”图形,从第一行开始,其的最左边和最右边必须是同一种颜色且都不为零,于是,我们就可以据此编程。

#include<bits/stdc++.h>
using namespace std;
#define IO() ios::sync_with_stdio(false);\
             cin.tie(NULL);\
             cout.tie(NULL);
#define MULTICASE int _;cin >> _;while(_ --)
const int N = 505;
char s[N][N];
int ok[N][N];
int n, m;

int check(int x, int y)
{
    int ans = 1;
    int pos = 1;
 
    for(int i = x + 1;i <= n;i ++)
    {
        if(y - pos <= 0 || y + pos > m)break;
        if(ok[i][y - pos] != ok[i][y + pos] || ok[i][y - pos] == 0 || ok[i][y + pos] == 0)return ans;
        ans ++;pos ++;
    }
    return ans;
}


main(){
    IO();
    MULTICASE
    {
        cin >> n >> m;
        memset(ok, 0, sizeof ok);
        for(int i = 1;i <= n;i ++)
            cin >> (s[i] + 1);
 
        int ans = 0;
        for(int i = 1;i <= n;i ++)
        {
            int state = 0;
            for(int j = 1;j <= m;j ++)
            {
                if(s[i][j] == '*')
                {
                    state ++;
                    while(s[i][j] == '*')
                        ok[i][j] = state, j ++;
                }
 
            }
        }
        for(int i = 1;i <= n;i ++)
        {
            for(int j = 1;j <= m;j ++)
            {
                if(s[i][j] == '*')
                    ans += check(i, j);
            }
        }
 
        cout << ans << '\n';
    }
}

C. Random Events
自后向前找出最后无序的位置,并记为 x x x,后输入位置与概率 p p p,若当前输入的数 ≥ x ≥x x,则将总概率乘于 ( 1 − p ) (1-p) (1p),最后让总概率 p a l l = 1 − p a l l p_{all}=1-p_{all} pall=1pall即可。

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define show(x) cerr << #x << " = " << x << '\n'
#define IO() ios::sync_with_stdio(false);\
             cin.tie(NULL);\
             cout.tie(NULL);
#define MULTICASE int _;cin >> _;while(_ --)
const int N = 100100;
int c[N];

main(){
    IO();
    MULTICASE
    {
        int n, m;
        cin >> n >> m;

        for(int i = 1;i <= n;i ++)
            cin >> c[i];

        int x;
        for(x = n;x;x --)
        {
            if(c[x] != x)break;
        }

        double ans = 1;
        for(int i = 1;i <= m;i ++)
        {
            int a;
            double b;
            cin >> a >> b;
            if(a >= x)
                ans *= (1 - b);
        }

        if(x == 0)
        {
            cout << "1.000000000" << endl;
            continue;
        }

        ans = 1 - ans;
        cout << fixed << setprecision(9) << ans << endl;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值