Codeforces Round #293 (Div. 2) 总结

来源:互联网 发布:软件培训师收入 编辑:程序博客网 时间:2024/06/05 15:18
A. Vitaly and Strings
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.

During the last lesson the teacher has provided two strings s and t to Vitaly. The strings have the same length, they consist of lowercase English letters, string s is lexicographically smaller than string t. Vitaly wondered if there is such string that is lexicographically larger than string s and at the same is lexicographically smaller than string t. This string should also consist of lowercase English letters and have the length equal to the lengths of strings s and t.

Let's help Vitaly solve this easy problem!

Input

The first line contains string s (1 ≤ |s| ≤ 100), consisting of lowercase English letters. Here, |s| denotes the length of the string.

The second line contains string t (|t| = |s|), consisting of lowercase English letters.

It is guaranteed that the lengths of strings s and t are the same and string s is lexicographically less than string t.

Output

If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).

If such string exists, print it. If there are multiple valid strings, you may print any of them.

Sample test(s)
input
ac
output
b
input
aaazzz
output
kkk
input
abcdefgabcdefh
output
No such string
Note

String s = s1s2... sn is said to be lexicographically smaller than t = t1t2... tn, if there exists such i, thats1 = t1, s2 = t2, ... si - 1 = ti - 1, si < ti.

解:给你两个字符串a,b,然后让你输出一个字符串,这个字符串c要求满足 a<c<b。

#include<stdio.h>#include<string.h>#include<string>#include<iostream>#include<algorithm>using namespace std;const int maxm=1e2+10;string a,b;int main(){    //freopen("standard input","w",stdin);   // freopen("standard output","r",stdout);    while(cin>>a>>b)    {        int ok=1;        a[a.length()-1]++;        for(int i=a.length()-1;i>=0;i--)        {            if(a[i]>'z')            {                a[i]='a';                a[i-1]++;            }        }        if(a==b)        {            cout<<"No such string"<<endl;        }        else        {            cout<<a<<endl;        }    }    return 0;}

B. Tanya and Postcard
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.

The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".

Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.

Input

The first line contains line s (1 ≤ |s| ≤ 2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.

The second line contains line t (|s| ≤ |t| ≤ 2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.

Here |a| means the length of the string a.

Output

Print two integers separated by a space:

  • the first number is the number of times Tanya shouts "YAY!" while making the message,
  • the second number is the number of times Tanya says "WHOOPS" while making the message.
Sample test(s)
input
AbCDCbA
output
3 0
input
ABCabc
output
0 3
input
abacabaAbaCaBA
output
3 4
解:题目大意是给一个模板串a,以及另一个长度大于模板串的串b,两个字符集均为大小写英文字母。从b中选出字符构造串c使得c尽量与模板串a相同,优先让a和c相同位置上的字符字母和大小写均相同,如果无法大小写相同,尽量让字母相同。输出c和a中二者都相同和只有字母相同的数量。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxm=1e6+10;char s[maxm];char t[maxm];int vis[30],vit[30];int vis1[30],vit1[30];int main(){    while(scanf("%s%s",s,t)!=EOF)    {        memset(vis,0,sizeof(vis));        memset(vit,0,sizeof(vit));        memset(vis1,0,sizeof(vis1));        memset(vit1,0,sizeof(vit1));        int count=0,sum=0;        int len1=strlen(s),len2=strlen(t);        for(int i=0;i<len1;i++)        {            if(s[i]>='A'&&s[i]<='Z')            {                vis[s[i]-'A']++;            }            else            {                vis1[s[i]-'a']++;            }        }        for(int i=0;i<len2;i++)        {            if(t[i]>='A'&&t[i]<='Z')            {                vit[t[i]-'A']++;            }            else            {                vit1[t[i]-'a']++;            }        }        for(int i=0;i<26;i++)//大写或小写一样的情况        {            int x=min(vis[i],vit[i]);            int y=min(vis1[i],vit1[i]);            count+=x;            count+=y;            vis[i]-=x;            vit[i]-=x;            vis1[i]-=y;            vit1[i]-=y;        }        for(int i=0;i<26;i++)//大写对小写或小写对大写的情况        {            int x=min(vis[i],vit1[i]);            int y=min(vit[i],vis1[i]);            sum+=x;            sum+=y;        }        printf("%d %d\n",count,sum);    }    return 0;}

C. Anya and Smartphone
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).

Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture — press the icon of the required application exactly once to launch it.

After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.

All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.

Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?

Note that one application may be launched multiple times.

Input

The first line of the input contains three numbers n, m, k (1 ≤ n, m, k ≤ 105) — the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.

The next line contains n integers, permutation a1, a2, ..., an — the initial order of icons from left to right in the menu (from the first to the last one), ai —  is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.

The third line contains m integers b1, b2, ..., bm(1 ≤ bi ≤ n) — the ids of the launched applications in the planned order. One application may be launched multiple times.

Output

Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order.

Sample test(s)
input
8 3 31 2 3 4 5 6 7 87 8 1
output
7
input
5 4 23 1 5 2 44 4 4 4
output
8
Note

In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.

After application 7 is launched, we get the new arrangement of the icons — (123)(457)(68). To launch it Anya makes 3 gestures.

After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.

After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.

In total, Anya makes 7 gestures.


题意:就是求m次登陆的总操作次数,总共n个APP,每一页最多k个,每滑动一次翻页算一次操作,登陆算一次操作,每次开始都在第一页,相当于在第几页就要几次操作,登陆后的APP和他前面的交换位置,即也能换页码
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define LL long longconst LL maxm=1e5+10;LL a[maxm];LL b[maxm];int main(){    LL n,m,k;    while(scanf("%lld%lld%lld",&n,&m,&k)!=EOF)    {        LL x;        for(LL i=0;i<n;i++)        {            scanf("%lld",&x);            x--;            a[i]=x;//代表值为数组a中第i个元素为x;            b[x]=i;//代表元素x的位置为i;        }        LL sum=0;        for(LL i=0;i<m;i++)        {            scanf("%lld",&x);            x--;            sum+=b[x]/k+1;//操作次数            if(b[x])            {                LL y=a[b[x]-1];//x前一个元素的值                swap(a[b[x]],a[b[y]]);//交换两个元素的值                swap(b[x],b[y]);//交换两个元素的位置            }        }        printf("%lld\n",sum);    }    return 0;}

D. Ilya and Escalator
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.

Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him.

Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds.

Your task is to help him solve this complicated task.

Input

The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 20000 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point.

Output

Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10 - 6.

Sample test(s)
input
1 0.50 1
output
0.5
input
1 0.50 4
output
0.9375
input
4 0.20 2
output
0.4

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxm=2e3+10;double dp[maxm][maxm];int main(){    int n,t;    double p;    while(scanf("%d%lf%d",&n,&p,&t)!=EOF)    {        double sum=0;        memset(dp,0,sizeof(dp));        dp[0][0]=1;        for(int i=1;i<=t;i++)        {            for(int j=n;j>=0;j--)            {                if(j==n)                    dp[i][j]=dp[i-1][j-1]*p+dp[i-1][j];////第i秒有n个人的概率等于第i-1秒有j-1个人的概率乘第i秒第j个人进电梯的概率加上第i - 1秒电梯就已经有n个人的概率                else if(j!=0)                    dp[i][j]=dp[i-1][j-1]*p+dp[i-1][j]*(1-p);// //这里dp[i - 1][j]要乘(1 - p)表示第i秒排头不进电梯                else                    dp[i][j]=dp[i-1][j]*(1-p);//第i秒电梯里没人的概率为第i-1秒电梯里没人的概率乘(1 - p)表示第i秒时排头不进电梯            }        }        for(int i=1;i<=t;i++)        {            sum+=(dp[t][i]*i);        }        printf("%0.7f\n",sum);    }    return 0;}

0 0