[跳转](http://codeforces.com/contest/1187 “Codeforces”)
A - Stickers and Toys
Description
n个彩蛋放了s个Sticker和t个toy,至少选多少个才能得到1个sticker和1个toy
抽屉原理
Code
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int T,s,n,t;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&s,&t);
int c = max(s,t);
printf("%d
",c - (s + t - n) + 1);
}
return 0;
}
B. Letters Shop
Analysis
按顺序存下每个字母出现的位置,找最大的
Code
//#pragma GCC optimize(2)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define N 200101
using namespace std;
char s[N],t[N];
int n,m;
vector<int> pos[27];
inline void solve()
{
int timer[26] = {0};
int ans = 0;
int len = strlen(t);
for(int i = 0;i < len;++i)
{
ans = max(ans,pos[t[i] - 'a'][timer[t[i] - 'a']]);
++timer[t[i] - 'a'];
}
printf("%d
",ans);
}
int main()
{
scanf("%d",&n);
scanf("%s",s);
for(int i = 0;i < n;++i)
{
pos[s[i] - 'a'].push_back(i + 1);
}
scanf("%d",&m);
for(int i = 0;i < m;++i)
{
scanf("%s",t);
solve();
}
return 0;
}