zoukankan      html  css  js  c++  java
  • Codeforces Round #449 (Div. 2)

    A. Scarborough Fair
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output
    Are you going to Scarborough Fair?

    Parsley, sage, rosemary and thyme.

    Remember me to one who lives there.

    He once was the true love of mine.

    Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.

    Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.

    Although the girl wants to help, Willem insists on doing it by himself.

    Grick gave Willem a string of length n.

    Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.

    Grick wants to know the final string after all the m operations.

    Input

    The first line contains two integers n and m (1 ≤ n, m ≤ 100).

    The second line contains a string s of length n, consisting of lowercase English letters.

    Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ nc1, c2 are lowercase English letters), separated by space.

    Output

    Output string s after performing m operations described above.

    Examples
    input
    3 1
    ioi
    1 1 i n
    output
    noi
    input
    5 3
    wxhak
    3 3 h x
    1 5 x a
    1 3 w g
    output
    gaaak
    Note

    For the second example:

    After the first operation, the string is wxxak.

    After the second operation, the string is waaak.

    After the third operation, the string is gaaak.

    A手速过题,从l到r的是什么进行替换,但是这个题数据量要很多的时候怎么办呢,区间更新?

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n,m;
        cin>>n>>m;
        string s;
        cin>>s;
        int l,r;
        char c1,c2;
        while(m--)
        {
            cin>>l>>r>>c1>>c2;
            for(int i=l-1;i<r;i++)
                if(s[i]==c1)
                s[i]=c2;
        }
        cout<<s;
        return 0;
    }
    B. Chtholly's request
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output
    — Thanks a lot for today.

    — I experienced so many great things.

    — You gave me memories like dreams... But I have to leave now...

    — One last request, can you...

    — Help me solve a Codeforces problem?

    — ......

    — What?

    Chtholly has been thinking about a problem for days:

    If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.

    Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.

    Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!

    Input

    The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).

    Output

    Output single integer — answer to the problem.

    Examples
    input
    2 100
    output
    33
    input
    5 30
    output
    15
    Note

    In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.

    In the second example, .

     直接找第k个数有怎样的规律,没做出来,绝望

    #include<stdio.h>
    typedef long long ll;
    ll la(int x)
    {
        ll t=x,b=0;
        while(x)
        {
            t*=10;
            b=b*10+x%10;
            x=x/10;
        }
        return t+b;
    }
    int main()
    {
        int k,p;
        scanf("%d%d",&k,&p);
        ll ans=0;
        while(k--)
            ans=(ans+la(k+1))%p;
        printf("%lld",ans);
        return 0;
    }
    C. Nephren gives a riddle
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output
    What are you doing at the end of the world? Are you busy? Will you save us?

    Nephren is playing a game with little leprechauns.

    She gives them an infinite array of strings, f0... ∞.

    f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".

    She wants to let more people know about it, so she defines fi =  "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.

    For example, f1 is

    "What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.

    It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.

    Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).

    Can you answer her queries?

    Input

    The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.

    Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).

    Output

    One line containing q characters. The i-th character in it should be the answer for the i-th query.

    Examples
    input
    3
    1 1
    1 2
    1 111111111111
    output
    Wh.
    input
    5
    0 69
    1 194
    1 139
    0 47
    1 66
    output
    abdef
    input
    10
    4 1825
    3 75
    3 530
    4 1829
    4 1651
    3 187
    4 584
    4 255
    4 774
    2 474
    output
    Areyoubusy
    Note

    For the first two examples, refer to f0 and f1 given in the legend.

    大概是个模拟题,字符串处理下,注意会越界的

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll a[100005];
    string s1="What are you doing at the end of the world? Are you busy? Will you save us?";
    string s21="What are you doing while sending "",s22 = ""? Are you busy? Will you send "",s23 = ""?";
    char la(int x, ll n)
    {
        if(n>a[x])return '.';
        if(!x)return s1[n - 1];
        if(n<=s21.size())return s21[n-1];
        n-=s21.size();
        if(n<=a[x-1])return la(x-1,n);
        n-=a[x-1];
        if(n<=s22.size())return s22[n-1];
        n-=s22.size();
        if(n<=a[x-1])return la(x-1,n);
        n-=a[x-1];
        return s23[n-1];
    }
    int main()
    {
        a[0]=s1.size();
        for (int i=1; i<=100000; i++)
        {
            a[i]=2ll*a[i-1]+s21.size()+s22.size()+s23.size();
            if(a[i]>2e18)a[i]=2e18;
        }
        int q;
        cin>>q;
        while (q--)
        {
            ll n,l;
            cin>>n>>l;
            cout<<la(n,l);
        }
        return 0;
    }
  • 相关阅读:
    Elementary Methods in Number Theory Exercise 1.2.25
    Elementary Methods in Number Theory Exercise 1.2.14
    图解欧几里德算法
    图解欧几里德算法
    Elementary Methods in Number Theory Exercise 1.2.14
    Android中的长度单位详解(dp、sp、px、in、pt、mm)
    分享下多年积累的对JAVA程序员成长之路的总结
    android异常之都是deamon惹的祸The connection to adb is down, and a severe error has occured.
    TomatoCartv1.1.8.2部署时报错
    JavaScript浏览器对象之二Document对象
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7989546.html
Copyright © 2011-2022 走看看