向来赛完不写解题报告就会时运Down,以后不敢了Q^Q
这场比赛是相对较为简单,容易想到思路,适宜冲紫名的一场,但可惜Pretest数据可能弱了些让大家过的太爽了于是FST就多了起来反而掉分现象普及。
那么,一个个来看看吧
A. Vitaly and Strings
time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVitaly 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!
InputThe 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.
OutputIf 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)inputaoutput
c
binput
aaaoutput
zzz
kkkinput
abcdefgoutput
abcdefh
No such stringNote
String s = s1s2... sn is said to be lexicographically smaller than t = t1t2... tn, if there exists such i, that s1 = t1, s2 = t2, ... si - 1 = ti - 1, si < ti.
简单来说,给了两个字符串,问他们之间存在字典序夹在二者之间的字符串嘛?有的话随便输出一个,没有的话输出“No such string”,题目中已经告知了s一定字典序小于t,那么s的最后一位加一看看是不是和t一样不就行了嘛?一样就是不存在,不一样就输出咯?
嘿嘿,有坑哦~ 如果末位是z怎么办,如果末位是两个、三个……n个z怎么办呢?这不是数字可以9变成0然后进位哦~ 对了,我们自己用while写一个类似进位的操作不久好了嘛?
Code:
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
bool cmp(const int a, const int b)
{
return a > b;
}
int main()
{
string s,t; cin>>s>>t;
int l=s.length()-1;
while(s[l]=='z')
{
s[l]='a';
l--;
}
s[l]=s[l]+1;
if(s==t) cout<<"No such string";
else cout<<s;
return 0;
}
说有一个小盆友他在报纸上剪下字来拼一个明信片,如果和自己想的字符一样而且大小写也一样了她就说“YAY”,如果字符一样大小写不一样她就说“Whoops”
要求YAY最多的情况中Whoops最多时的两者数量。
简单的说,给定两个字符串,问在第二个字符串中有多少个a中的严格区分大小写字符,排除掉这些字符后不严格区分大小写的有多少个。
因为字符串不长,可以暴力枚举。
先读一遍s得知需要哪些东西(这里想想我当时为啥hash呢,map简直轻松愉快呀,读者可以试试使用map<char,int> mp,然后mp[a]++这样的操作,会比起数组hash来惬意的多),然后在t中找,严格区分大小写的数完记得减掉,然后再找一次不区分大小写的,输出两个数字即可。
Code:
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
bool cmp(const int a, const int b)
{
return a > b;
}
int cntl[26]={0},cntu[26]={0};//cnt
int nedl[26]={0},nedu[26]={0};//need
int main()
{
int yay=0,whoops=0;
string s,t; cin>>s>>t;
for(int i=0;i<s.length();i++)
{
if(isupper(s[i])) nedu[s[i]-'A']++;
else nedl[s[i]-'a']++;
}
for(int i=0;i<t.length();i++)
{
if(isupper(t[i])) cntu[t[i]-'A']++;
else cntl[t[i]-'a']++;
}
for(int i=0;i<26;i++)
{
if(nedl[i]!=0 && cntl[i]!=0)
{
int p=min(nedl[i],cntl[i]);
nedl[i]-=p,cntl[i]-=p,yay+=p;
}
if(nedu[i]!=0 && cntu[i]!=0)
{
int p=min(nedu[i],cntu[i]);
nedu[i]-=p,cntu[i]-=p,yay+=p;
}
}
for(int i=0;i<26;i++)
{
if(nedl[i]!=0 && cntu[i]!=0)
{
int p=min(nedl[i],cntu[i]);
nedl[i]-=p,cntu[i]-=p,whoops+=p;
}
if(nedu[i]!=0 && cntl[i]!=0)
{
int p=min(nedu[i],cntl[i]);
nedu[i]-=p,cntl[i]-=p,whoops+=p;
}
}
cout<<yay<<' '<<whoops<<endl;
return 0;
}
C. Anya and Smartphone
time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnya 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.
InputThe 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.
OutputPrint a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order.
Sample test(s)input8 3 3output
1 2 3 4 5 6 7 8
7 8 1
7input
5 4 2output
3 1 5 2 4
4 4 4 4
8Note
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 3gestures.
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.
说有个智能手机,上面有n个APP,我要点其中的m个,每页最多可以放k个APP。
当我每次点击一个APP的时候,如果这个APP不在第一位,那么他就和他前面的一个APP调换位置,问我们按照顺序点击那m个APP要做多少个手势(滑动到下一页要一个手势,点击是一个手势,每点击一个APP出来都回到第一页)
点击某个APP需要的手势的个数其实就是(pos/k)+(pos%k==0?0:1),即这个APP当前所在的位置除以每页最多放置的APP数,向上取整,因为我们需要滑动(当前所在页数-1)+点击1次=当前所在页数。
然后就是每次点击要前移一位的实现了:
if(pos>1)
{
int t=fdnum[pos-1];
fdnum[pos-1]=now;
fdpos[now]=pos-1;
fdnum[pos]=t;
fdpos[t]=pos;
}
我用的方法是:数组1:每个位置对应当前位置的APP编号,数组2:每个APP编号当前所在的位置,然后借助临时变量t进行swap操作。
当然别忘了他就在第一页的时候不用和前一个调换位置哦。
然后,坑来了——
孩子们永远是那句话……int不是好东西啊,LL大法好啊,动不动int就溢出了烦不烦呢!明明就前300可以紫名了你就是不开心溢出让我FST,叹气……
Code:
#include <map>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
bool cmp(const int a, const int b)
{
return a > b;
}
map<int,int> fdpos,fdnum; //num->pos & pos->num
int main()
{
fdpos.clear();
fdnum.clear();
long long ans=0; // LL大法好……
int n,m,k;cin>>n>>m>>k;
for(int i=1;i<=n;i++)
{
int now;scanf("%d",&now);
fdpos[now]=i;
fdnum[i]=now;
}
for(int i=1;i<=m;i++)
{
int now;scanf("%d",&now);
int pos=fdpos[now];
ans+=(pos/k)+(pos%k==0?0:1);
//swap
if(pos>1)
{
int t=fdnum[pos-1];
fdnum[pos-1]=now;
fdpos[now]=pos-1;
fdnum[pos]=t;
fdpos[t]=pos;
}
}
cout<<ans;
return 0;
}
没错这就是个DP……
啊对了题意啊题意……
有个无限长的电梯,有n个人一列纵队在排队上电梯,每个人只能在前头都没人了的时候才能上电梯,每秒钟,有p的概率排在第一的人上了电梯,问:t秒后,电梯上人数的数学期望……
数学你好……概率学啦……
用dp[i][j]来表示当i个人排队时在第t秒电梯上人数的数学期望。
那么我们知道dp[i][j]应该等于
当[(i-1个人,j-1秒)时的期望+1] * p (这个人上去了)
加上 当[(i个人,j-1秒)时的期望 * (1-p) (这个人没上去)
具体的看看代码吧
Code:
#include<bits/stdc++.h>
double dp[2005][2005];
int main()
{
int n,t,i;
double p;
scanf("%d%lf%d",&n,&p,&t);
for(i=1;i<=n;i++)
{
for(int j=1;j<=t;j++)
dp[i][j]=(p*(1+dp[i-1][j-1])+(1-p)*(dp[i][j-1]));
}
printf("%.6lf",dp[n][t]);
return 0;
}