您的位置:首页 > 其它

codeforces 758B

2018-01-13 15:34 375 查看
题目链接:点击打开题目

题意比较明确,就是让你填上 'R',
'B',
'Y'
and 'G'。使任何相邻的四个都没有一样的元素,他说了,肯定有答案,所以,就变成了一道思维题。

思路:他说,每个字符最起码出现一次,还要求相邻的四个无一样的元素,那么,我们就可以认为,四个一组,每个字符出现的位置都是恰好的位置,如果对这个位置下标%4,肯定就是前四个元素,我们得出来前四个元素的排列了,后面的都顺着来就行,然后,,,就没有然后了。对了,不要忘记统计!在四个位置出现多少次

My ugly code

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <stack>
#include <vector>
#include <iostream>
#define ll long long
using namespace std;

int a[256],b[256];

int main(){
string s;

while(cin >> s){
int len=s.size();
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=0;i<len;i++){
if(s[i] == '!'){
b[i%4]++;
}
else{
a[s[i]]=i%4;
}
}
printf("%d %d %d %d\n",b[ a['R'] ],b[ a['B'] ],b[ a['Y'] ],b[ a['G'] ]);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: