#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <list>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <iterator>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double E = exp(1.0);
const int MOD = 1e9+7;
const int MAX = 1e5+5;
int n;
string str;
int res;
int flag[26+5];
int main()
{
cin >> n;
cin >> str;
int cnt = 0;// 顾客接受不到服务的个数
res = n;// 剩余的位置数
for(int i = 0; i < (int)str.length(); i++)
{
int c = str[i] - 'A' + 1;
if(!flag[c])
{
if(res >= 1)
{
flag[c] = 1; res--;
}
else
{
cnt++;
i++;// 找不到座位会马上退出,所以下一个也肯定是一样的c
}
}
else
{
flag[c] = 0;
res++;
}
}
cout << cnt << endl;
return 0;
}
51NOD1912 咖啡馆题解法
最新推荐文章于 2024-07-18 10:21:10 发布