C. Diluc and Kaeya——Codeforces Round #724 (Div. 2)

Posted 出尘呢

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C. Diluc and Kaeya——Codeforces Round #724 (Div. 2)相关的知识,希望对你有一定的参考价值。

C. Diluc and Kaeya
一开始就想到了GCD,但是计数没想到。。
打开思路,也多见见,不难理解

//wa原因:不均分 
//ac反思:计数方法,之前要有过等于之前相同状态记录一次 
#include<bits/stdc++.h>
#ifdef LOCAL
FILE*FP=freopen("text.in","r",stdin);
#endif
using namespace std;
int t,n;
char a[500005];
map<pair<int,int>,int>m;
signed main()
	scanf("%d",&t);
	while(t--)
		scanf("%d",&n);
		scanf("%s",a);
		int cd=0,ck=0;
		for(int i=0;i<n;i++)
			if(a[i]=='D')cd++;
			else if(a[i]=='K')ck++;
			printf("%d",++m[make_pair(cd/__gcd(cd,ck),ck/__gcd(cd,ck))]);
			putchar((i==n-1)?'\\n':' ');
		
		m.clear();
	
	return 0;

以上是关于C. Diluc and Kaeya——Codeforces Round #724 (Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章