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

来源:互联网 发布:多用户商城源码 编辑:程序博客网 时间:2024/05/16 10:33

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:

qwertyuiopasdfghjkl;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
Rs;;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 ≤ 103a1 + 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
52 7 3 4 931 25 11
output
153
Note

For the sample input:

  • The worms with labels from [12] are in the first pile.
  • The worms with labels from [39] are in the second pile.
  • The worms with labels from [1012] are in the third pile.
  • The worms with labels from [1316] are in the fourth pile.
  • The worms with labels from [1725] 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 21 32 34 4
output
655
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;}










0 0
原创粉丝点击