A - A Blend of Springtime
题意:给你一个字符串,字母表示花的种类.规定:花凋谢的时候可以将相邻两个地方给染色,问是否存在一个地方有所有的颜色.
思路:只要有三个连续的位置由三个不同的字母填充就可以.
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
string s;
cin>>s;
int l = s.length();
if(l<3)
{
cout<<"No\n";
return 0;
}
int flag = 0;
//int i = 0;
for(int i = 0 ;i <= l-3;i++)
{
if(s[i]!=s[i+1]&&s[i+1]!=s[i+2]&&s[i]!=s[i+2]&&s[i]!='.'&&s[i+1]!='.'&&s[i+2]!='.')
{
flag = 1;
break;
}
}
// cout<< 'A'+'C'+'B';
if(flag)
cout<<"Yes\n";
else cout<<"No\n";
}
B - A Tide of Riverscape
题意:给你两个数字n和p,分别表示字符串的长度和周期,给你一个由0,1和逗号组成的字符串,让你判断是否任意间隔p个的字符的两个字符不相同,如果都不相同输出no,反之输出yes,并且.可以转化为0或者一.
思路:用滑动窗口的方法 去遍历字符串就行
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
int n,p;
string s;
cin>>n>>p;
cin>>s;
LL num;
int flag = 0;
for( int i = 0; i < s.length(); i ++ )
{
if( i+p < s.length() )
{
if( s[i] != s[i+p]||s[i] == s[i+p] && s[i] == '.')
{
if(s[i] == s[i+p])
{
s[i]='0', s[i+p] = '1';
}
else
{
if(s[i] == '0')
{
s[i+p] = '1';
}
else if(s[i] == '1')
{
s[i+p] = '0';
}
else
{
if(s[i+p] == '0')
{
s[i] = '1';
}
else
{
s[i] = '0';
}
}
}flag = 1;
break;
}
}
}
if(flag)
{
for(int i = 0; i < s.length();i++)
{
if(s[i] == '.')
{
s[i] = '0';
}
}
cout<<s<<endl;
}
else
{
cout<<"No";
}
}
D - Infinity Gauntlet
题意:六种颜色分别对应六种元素,给你n个颜色,问你还剩下什么元素;
思路:用map对应,然后用一个标记数组储存是否被标记过,最后输出没被标记的元素就行
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
//map<string,string> a = {{"purple","Power"},{"green","Time"},{"blue","Space"},{"orange","Soul"},{"red","Reality"},{"yellow","Mind"}};
map<string,int>a = {{"purple",0},{"green",1},{"blue",2},{"orange",3},{"red",4},{"yellow",5}};
string ccc[6] = {"Power","Time","Space","Soul","Reality","Mind"};
int main()
{
int n;
cin>>n;
int res = 6-n;
int s[6] = {0};
for(int i = 0;i < n;i++){
string t;
cin>>t;
s[a[t]] = 1;
}
cout<<res<<endl;
for(int i = 0;i <=5;i++)
{
if(s[i]==0)
cout<<ccc[i]<<endl;
}
}
E - High School: Become Human
题意:让你比较x^y和y^x的大小
思路:比较对应的对数大小就行,特别判断等号:如果两个数相等或者一个等于2,另一个等于4那么两个相等.
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,b;
cin>>a>>b;
if(a==b||a==2&&b==4||a==4&&b==2)
cout<<"="<<endl;
else
{
double x = b*log(a),y = a*log(b);
if(x>y)
cout<<">"<<endl;
else if(x<y)
cout<<"<"<<endl;
}
}