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;
}
题意比较明确,就是让你填上 '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;
}
相关文章推荐
- 【codeforces 758B】Blown Garland
- Codeforces 758B-Blown Garland
- Codeforces 630D Hexagons!
- CodeForces 500B New Year Permutation(序列的变换)
- Codeforces 176B Word Cut
- codeforces 333B - Chips
- codeforces 544D Destroying Roads (最短路)
- CodeForces 772C. Vulnerable Kerbals
- codeforces 456A
- codeforces 660C (尺取法 水~)
- codeforces 716B字符串水题
- codeforces189 A. Cut Ribbon【完全背包】
- codeforces 13A. Numbers
- codeforces 550B Preparing Olympiad(枚举)
- Codeforces 369D Valera and Fools【思维+dp】
- CodeForces - 867B Save the problem! 构造
- Codeforces 660D Number of Parallelograms
- 【codeforces 510 B Misha and Changing Handles】
- Codeforces 940-A
- codeforces 328A. IQ Test