题目大意:
四种颜色的灯排成一排,一些灯的颜色是已知的,另外的灯已损坏。并且知道每连续的四个灯中一定有四种颜色。问每种颜色的灯有多少个是已经损坏的.
题解:
这道题是那种看着高端大气上档次,画一个样例就变成sb题的那种题。
我们发现,这个序列肯定是一个长度为4的子序列不断重复得来的序列。。
并且...并且什么,这就够了.
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 128;
char s[maxn];
int ans[maxn];
int main(){
scanf("%s",s+1);
int n = strlen(s+1);
int a,b,c,d;
for(int i=1;i<=n;++i){
switch(s[i]){
case 'R':a = i%4;break;
case 'B':b = i%4;break;
case 'Y':c = i%4;break;
case 'G':d = i%4;break;
case '!':ans[i%4]++;break;
}
}
printf("%d %d %d %d
",ans[a],ans[b],ans[c],ans[d]);
getchar();getchar();
return 0;
}