codeforces.com/contest/897/

A

#include<stdio.h>


int main()
{
    int n, m;
    char s[102];
    while(scanf("%d%d%s", &n, &m, s) != EOF) {
        while(m--) {
            int l, r;
            char c1, c2;
            scanf("%d%d %c %c", &l, &r, &c1, &c2);
            for(int i = l; i <= r; ++i) {
                if(s[i - 1] == c1) {
                    s[i - 1] = c2;
                }
            }
        }
        puts(s);
    }
    return 0;
}

B

#include<stdio.h>

const int MAXN = (int)1e5 + 5;
int k, p, cnt, t;
typedef long long ll;

int mod_pow(int a, int n) {
    int res = 1;
    while(n) {
        if(n&1) res = 1LL * res * a % p;
        a = 1LL * a * a % p;
        n >>= 1;
    }
    return res;
}

int f(int j, int i) {
    return 1LL * mod_pow(10, i) * j % p;
}

int dfs(int i, int sum, bool fg) {
    if(cnt == k) return 0;
    if(i == t / 2) {
        ++cnt;
        return sum;
    }
    int res = 0;
    if(fg) res = dfs(i - 1, sum, true);
    for(int j = 1; j <= 9; ++j) {
        res += dfs(i - 1, ((sum + f(j, i - 1))%p + f(j, t - i)) % p, true);
        res %= p;
    }
    return res;
}

int work() {
    int res = 0;
    cnt = 0;
    for(int i = 2; cnt <= k; i += 2) {
        res += dfs(t = i, 0, false);
        res %= p;
        if(cnt == k) break;
    }
    return res;
}

int main()
{
    while(scanf("%d%d", &k, &p) != EOF) {
        int ans = work();
        printf("%d\n", ans);
    }
    return 0;
}

C

#include<stdio.h>
#include<string.h>

typedef long long ll;
const char s0[] = "What are you doing at the end of the world? Are you busy? Will you save us?";
const char s1[] = "What are you doing while sending \"";
const char s2[] = "\"? Are you busy? Will you send \"";
const char s3[] = "\"?";
int l1, l2, l3, len, l0;

void init() {
    l0 = strlen(s0);
    l1 = strlen(s1);
    l2 = strlen(s2);
    l3 = strlen(s3);
    len = l1 + l2 + l3;
}

ll a(int k) {
    if(k >= 55) return 5152117973711847356;
    return (1LL<<k) * (len + l0) - len;
}

ll f(int i, int k) {
    switch(i) {
        case 0: return 0;
        case 1: return l1;
        case 2: return f(i - 1, k) + a(k - 1);
        case 3: return f(i - 1, k) + l2;
        case 4: return f(i - 1, k) + a(k - 1);
        case 5: return f(i - 1, k) + l3;
    }
}

char slove(int n, ll k) {
    if(n == 0 && k <= l0) return s0[k - 1];
    if(n == 0 && k > l0) return '.';
    if(k <= f(1, n)) return s1[k - 1];
    if(k <= f(2, n)) return slove(n - 1, k - f(1, n));
    if(k <= f(3, n)) return s2[k - f(2, n) - 1];
    if(k <= f(4, n)) return slove(n - 1, k - f(3, n));
    if(k <= f(5, n)) return s3[k - f(4, n) - 1];
    return '.';
}

int main()
{
    init();
    /*
    for(int i = 0; i <= 60; ++i) {
        printf("# %d %lld\n", i, a(i));
    }*/
    int T;
    while(scanf("%d", &T) != EOF) {
        while(T--) {
            int n;
            ll k;
            scanf("%d%lld", &n, &k);
            printf("%c", slove(n, k));
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值