51 Nod 放球游戏

 

 

 

1,模拟题

2,放在两边只是个幌子罢了,(放在中间和两边在无特殊情况下是一样的奖励

3,特殊情况,那么就是往中间放,对于每种颜色的球,最多得2点奖励 

接下来看下代码~

#include <stdio.h>
#include <stack>
#include <istream>
#include <map>
#include <math.h>
#include <string.h>
#include <set>
#include <vector>
#include <string>
using namespace std;
const int maxn = 1e5 + 1;

 

char str[maxn];
int RGB[3];
void check(int i)
{
if(str[i]=='R')RGB[0]++;
if(str[i]=='G')RGB[1]++;
if(str[i]=='B')RGB[2]++;
}
int main() {
int n;
scanf("%d",&n);
for(int i =1;i<=n;i++)
{
memset(RGB,0,sizeof(RGB));
scanf("%s",str);
int len = strlen(str);
if(len==1) {
printf("0\n");continue;
}
if(len==2){
printf("1\n");
continue;
}
int ans = 1;
check(0),check(1);
for(int j = 2;j<len;j++)
{
for(int k = 0;k<3;k++)
{
if(RGB[k]>=2)ans+=2;
else ans+=RGB[k];
}
check(j);
}
printf("%d\n",ans);
}
return 0;
}

 

posted @ 2018-04-03 16:20  Xzavieru  阅读(70)  评论(0编辑  收藏  举报