比赛 |
2024暑假C班集训C |
评测结果 |
WWWWWWWWWW |
题目名称 |
W&B |
最终得分 |
0 |
用户昵称 |
AeeE5x |
运行时间 |
2.115 s |
代码语言 |
C++ |
内存使用 |
3.75 MiB |
提交时间 |
2024-07-12 09:13:23 |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct nod{
int num;
char col;
};
int gcd(int x,int y){
if(x%y==0) return y;
return gcd(y,x%y);
}
int main(){
freopen("silly.in","r",stdin);
freopen("silly.out","w",stdout);
int t;scanf("%d",&t);
while(t--){
int n,bsum=0,wsum=0;
queue<nod> que;
scanf("%d",&n);
for(int i=1;i<=n;i++){
int k;char c;scanf("%d %c",&k,&c);
que.push((nod){k,c});
if(c=='B') bsum+=k;
else wsum+=k;
}
if(bsum==0||wsum==0){
printf("%d\n",max(bsum,wsum));
}else{
int q=gcd(bsum,wsum),bn=0,wn=0,ans=0;
bsum/=q,wsum/=q;
while(!que.empty()){
while(!que.empty()&&(bn<bsum||wn<wsum)){
if(que.front().col=='B') bn+=que.front().num;
else wn+=que.front().num;
que.pop();
}
ans++;
int tmp=min(bn/bsum,wn/wsum);
bn-=tmp*bsum,wn-=tmp*wsum;
}
printf("%d\n",ans);
}
}
return 0;
}