首页 > 其他分享 >Codeforces Round #271 (Div. 2) A B D

Codeforces Round #271 (Div. 2) A B D

时间:2023-03-03 13:03:36浏览次数:52  
标签:int Marmot Codeforces worms 271 input Div include Mole

http://codeforces.com/contest/474

A 水题 枚举每个字符即可

A. Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:

qwertyuiop asdfghjkl; zxcvbnm,./

Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input).

We have a sequence of characters he has typed and we want to find the original message.

Input

First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right).

Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard.

It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.

Output

Print a line that contains the original message.

Sample test(s) input R s;;upimrrfod;pbr output allyouneedislove

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<sstream>
#include<time.h>
#include<utility>
#include<malloc.h>
#include<stdexcept>
#include<iomanip>
#include<iterator>

using namespace std;

int n,m;
char a[3];
char b[10000];

char p[10000] = {"qwertyuiopasdfghjkl;zxcvbnm,./"};

int main ()
{
    scanf("%s",a);
    scanf("%s",b);
    int l = strlen(b);
    if (a[0] == 'L')
    {
        for(int i=0;i<l;i++)
        {
            for(int j=0;j<30;j++)
            {
                if (p[j] == b[i])
                {
                    printf("%c",p[j+1]);
                    continue;
                }
            }
        }
        printf("\n");
    }
    else if (a[0] == 'R')
    {
        for(int i=0;i<l;i++)
        {
            for(int j=0;j<30;j++)
            {
                if (p[j] == b[i])
                {
                    printf("%c",p[j-1]);
                    continue;
                }
            }
        }
        printf("\n");
    }
    return 0;
}


B. Worms time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.

Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with numbers a1 + 1 to a1 + a2 and so on. See the example for a better understanding.

Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.

Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.

Input

The first line contains a single integer n (1 ≤ n ≤ 105), the number of piles.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103, a1 + a2 + ... + an ≤ 106), where ai is the number of worms in the i-th pile.

The third line contains single integer m (1 ≤ m ≤ 105), the number of juicy worms said by Marmot.

The fourth line contains m integers q1, q2, ..., qm (1 ≤ qi ≤ a1 + a2 + ... + an), the labels of the juicy worms.

Output

Print m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number qi is.

Sample test(s) input 5 2 7 3 4 9 3 1 25 11 output 1 5 3 Note

For the sample input:

  • The worms with labels from [1, 2] are in the first pile.
  • The worms with labels from [3, 9] are in the second pile.
  • The worms with labels from [10, 12] are in the third pile.
  • The worms with labels from [13, 16] are in the fourth pile.
  • The worms with labels from [17, 25] are in the fifth pile.


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<sstream>
#include<time.h>
#include<utility>
#include<malloc.h>
#include<stdexcept>
#include<iomanip>
#include<iterator>

using namespace std;

int n,m;

long long  a[1100000];
long long p[1100000];
int b;

int main ()
{
    while (scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
            scanf("%I64d",&a[i]);

        long long  sum = 0;
        for(int i=0;i<n;i++)
        {
            for(int j = sum ;j<sum + a[i];j++)
                p[j] = i;

            sum+=a[i];
        }

        scanf("%d",&m);
        while (m--)
        {
            scanf("%d",&b);
            printf("%I64d\n",p[b-1]+1);
        }

    }
    return 0;
}




D题 dp 

D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output

We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.

But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.

Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).

Input

Input contains several test cases.

The first line contains two integers t and k (1 ≤ t, k ≤ 105), where t represents the number of test cases.

The next t lines contain two integers ai and bi (1 ≤ ai ≤ bi ≤ 105), describing the i-th test.

Output

Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).

Sample test(s) input 3 2 1 3 2 3 4 4 output 6 5 5 Note
  • For K = 2 and length 1 Marmot can eat (R).
  • For K = 2 and length 2 Marmot can eat (RR) and (WW).
  • For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
  • For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<sstream>
#include<time.h>
#include<utility>
#include<malloc.h>
#include<stdexcept>
#include<iomanip>
#include<iterator>

using namespace std;

int n,m;
int k,t;

int a,b;
int mod = 1000000007;
long long ans[100010];

int main ()
{
    while (scanf("%d %d",&t,&k)!=EOF)
    {
        for(int i=1;i<k;i++)
            ans[i] = 1;
        ans[k] = 2;

        for(int i=k+1;i<=100002;i++)
            ans[i] = (ans[i-1] + ans[i-k]) % mod;

        for(int i=2;i<=100002;i++)
            ans[i] = (ans[i] + ans[i-1]) % mod;

        for(int i=0;i<t;i++)
        {
            scanf("%d %d",&a,&b);
            long long  anss = (ans[b] - ans[a-1])%mod;
            if (anss < 0)
                    anss += mod;
            printf("%I64d\n",anss);
        }

    }
    return 0;
}










标签:int,Marmot,Codeforces,worms,271,input,Div,include,Mole
From: https://blog.51cto.com/u_15990681/6098476

相关文章

  • Codeforces Round #280 (Div. 2) A B C
    http://codeforces.com/contest/492A水题A.VanyaandCubestimelimitpertest1secondmemorylimitpertest256megabytes......
  • Codeforces Round #281 (Div. 2) A B
    http://codeforces.com/contest/493A第一次结构体开二维数组。。。A.VasyaandFootballtimelimitpertest2secondsmemorylimitper......
  • Codeforces Round #850 (Div. 2, based on VK Cup 2022 - Final Round)
    Preface补题,之前由于要准备开学考(其实只是临时抱佛脚罢了),所以好久没写题不过索性学校题目简单,微积分线代C程都满绩了(甚至溢出好多),思政被卡了一分满绩点,而大英不出所料3.7......
  • div水平垂直居中的四种方式
    div水平垂直居中的四种方式让div水平居中的方式,我所知道的就是以下这四种。目录div水平垂直居中的四种方式一、margin二、绝对定位三、子元素绝对定位父元素相对定位四、......
  • Educational Codeforces Round 55 (Rated for Div. 2) G. Petya and Graph 网络流|
    很经典,想记录一下网络流里有一个很典的trick,求最大获利转化成最小损失求最小损失转化成割边求的是max(边权和-边所连接的点权和),考虑把边看成左部点,把点看成右部点刚开......
  • Educational Codeforces Round 144 (Rated for Div. 2)
    链接EducationalCodeforcesRound144(RatedforDiv.2)只会两个题太弱了A题先打表找出一个很长的字符字串然后,用strstr查找找到yes找不到no#include<iostream>......
  • Codeforces 438D The Child and Sequence 势能线段树
    势能线段树|拉线段树题单时发现的这道花神游历各国的骚操作至今让我印象深刻,原来有名字所谓势能,大意就是原本你在高空,操作一点下降一点,势能变少一点..当你落地时,修改......
  • ABC-271解题报告
    C.Manga题意:有一本书有\(n\)卷,你需要从第一卷开始依次看,一旦没有某一卷就停止。在看之前你可以进行若干次操作,每次卖掉任意两卷并买新的任意一卷。问操作结束后最多能......
  • CFR-826-Div-3解题报告
    F.Multi-ColoredSegments题意:数轴上有\(n\)个线段,每个区间有一个颜色\(c\),对于每个线段,求与它颜色不同的线段中与它的最短距离。距离定义为两个线段中的点集最近的......
  • CFR-832-Div-2解题报告
    B.BANBAN题意:给你一个\(n\),生成一个字符串为BAN重复\(n\)遍。每次操作可以选择两个位置进行交换,问至少多少次交换后可以使该串不存在BAN的子序列。输出方案。......