#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 25010;
char s[MAXN];
int orp[125], nrp[125], t, n;
bool cmp(char a, char b) { return orp[a] < orp[b]; }//
int main()
{
cin >> t;
while (t--)
{
cin >> n >> s;
for (int i = 0; i < n; ++i)
orp[s[i]] = i;//将每个团队的最后那个人记录下来
sort(s, s + n, cmp);//将团队按照最后一个人的顺序排列起来
// cout<<"排列后的团队顺序"<<endl;
// for( int i = 0; i < n; ++i )
// cout<<s[i]<<' '<<endl;
for (int i = 0; i < n; ++i)
nrp[s[i]] = i;//排序后的每个团队的最后一个人的顺序
long long ans = 0;
for (int i = 0; i < n; ++i)
ans += abs(orp[s[i]] - nrp[s[i]]);//将 每个团队节省开始的时间乘以团队人数
cout << ans * 5 << endl;//一个时间段是5秒
}
return 0;
}
HNU 13320
最新推荐文章于 2021-01-13 19:01:10 发布