C. Diluc and Kaeya
求比率,也就是用 d 和 k 除以他们最大的公共因子, 就是比率(我居然傻逼的想着for循环找这个因子,这™不就gcd(d, k) 吗,笨死了)
map 存一下每一个所得的比率的个数,输出就完事了
仔细想想这题好像也很简单
注:任何数和0 的gcd都是它本身
#include<bits/stdc++.h>
using namespace std;
map <pair<int,int>, int> ma;
int n;
inline pair<int,int> cal(int d, int k)
{
int t = __gcd(d, k);
d /= t; k /= t;
return make_pair(d, k);
}
void work()
{
ma.clear();
int d = 0, k = 0;
string s; cin >> n >> s;
for(int i = 0; i < s.length(); ++i)
{
if(s[i] == 'D') ++d;
else ++k;
ma[cal(d, k)]++;
cout << ma[cal(d, k)] << " \n"[i == s.length()-1];
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while(t--) work();
return 0;
}