http://codeforces.com/contest/474
A 水题 枚举每个字符即可
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.
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.
Print a line that contains the original message.
R s;;upimrrfod;pbr
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;
}
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.
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.
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.
5 2 7 3 4 9 3 1 25 11
1 5 3
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
#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;
}