"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
The first and only line of input contains a non-empty string ss consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (|s|≤100|s|≤100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
.BAC.
Yes
AA..CB
No
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
题意:问串中是否存在连续的‘ABC’的全排列.
题解:模拟下即可。
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long double ll;
ll a[10005],b[10005];
int main()
{
string s;
cin>>s;
for(int i=2;i<s.size();i++)
{
if(s[i]!='.'&&s[i-1]!='.'&&s[i-2]!='.'&&s[i]!=s[i-1]&&s[i-1]!=s[i-2]&&s[i]!=s[i-2])
{
printf("Yes\n");return 0;
}
}
cout<<"No\n";
return 0;
}
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string ss of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer pp is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer pp is considered a period of string ss, if for all 1≤i≤|s|−p1≤i≤|s|−p, the ii-th and (i+p)(i+p)-th characters of ss are the same. Here |s||s| is the length of ss.
The first line contains two space-separated integers nn and pp (1≤p≤n≤20001≤p≤n≤2000) — the length of the given string and the supposed period, respectively.
The second line contains a string ss of nn characters — Mino's records. ss only contains characters '0', '1' and '.', and contains at least one '.' character.
Output one line — if it's possible that pp is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
10 7 1.0.1.0.1.
1000100010
10 6 1.0.1.1000
1001101000
10 9 1........1
No
In the first example, 77 is not a period of the resulting string because the 11-st and 88-th characters of it are different.
In the second example, 66 is not a period of the resulting string because the 44-th and 1010-th characters of it are different.
In the third example, 99 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them.
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long double ll;
int main()
{
int n;cin>>n;
string s;int p;cin>>p>>s;
int flag=0;
for(int i=0;i<n;i++)
{
if(s[i]=='.')
{
if(i+p<n)
{
flag=1;
if(s[i+p]=='1')s[i]='0';
else if(s[i+p]=='0') s[i]='1';
else
{
s[i]='1';s[i+p]='0';
}
break;
}
}
if(s[i]=='.')
{
if(i-p>=0)
{
flag=1;
if(s[i-p]=='1')s[i]='0';
else if(s[i-p]=='0')s[i]='1';
else if(s[i-p]=='.')
{
s[i]='1';s[i-p]='0';
}
break;
}
}
}
for(int i=0;i<s.size();i++)
{
if(i+p<n) if(s[i]!=s[i+p]) flag=1;
}
if(flag==1)
{
for(int i=0;i<n;i++) if(s[i]=='.')s[i]='1';
}
if(flag)
cout<<s<<endl;
else cout<<"No\n";
return 0;
}
"I've been here once," Mino exclaims with delight, "it's breathtakingly amazing."
"What is it like?"
"Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?"
There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.
The wood can be represented by a rectangular grid of nn rows and mm columns. In each cell of the grid, there is exactly one type of flowers.
According to Mino, the numbers of connected components formed by each kind of flowers are aa, bb, cc and dd respectively. Two cells are considered in the same connected component if and only if a path exists between them that moves between cells sharing common edges and passes only through cells containing the same flowers.
You are to help Kanno depict such a grid of flowers, with nn and mm arbitrarily chosen under the constraints given below. It can be shown that at least one solution exists under the constraints of this problem.
Note that you can choose arbitrary nn and mm under the constraints below, they are not given in the input.
The first and only line of input contains four space-separated integers aa, bb, cc and dd (1≤a,b,c,d≤1001≤a,b,c,d≤100) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively.
In the first line, output two space-separated integers nn and mm (1≤n,m≤501≤n,m≤50) — the number of rows and the number of columns in the grid respectively.
Then output nn lines each consisting of mm consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and 'D', representing Amaranths, Begonias, Centaureas and Dianthuses, respectively.
In case there are multiple solutions, print any. You can output each letter in either case (upper or lower).
5 3 2 1
4 7 DDDDDDD DABACAD DBABACD DDDDDDD
50 50 1 1
4 50 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ABABABABABABABABABABABABABABABABABABABABABABABABAB BABABABABABABABABABABABABABABABABABABABABABABABABA DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
1 6 4 5
7 7 DDDDDDD DDDBDBD DDCDCDD DBDADBD DDCDCDD DBDBDDD DDDDDDD
In the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
char s[55][55];
int check(int i,int j,char ch)
{
if(s[i][j-1]==ch) return 0;
if(s[i][j+1]==ch) return 0;
if(s[i+1][j]==ch) return 0;
if(s[i-1][j]==ch) return 0;
return 1;
}
int main()
{
int a,b,c,d;
int n=50;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i<=25)
s[i][j]='A';
else s[i][j]='B';
}
}
cin>>a>>b>>c>>d;
a--;b--;
for(int i=1;i<=25;i++)
{
for(int j=1;j<=n;j+=2)
{
if(b>0&&check(i,j,'B')) s[i][j]='B',b--;
else if(c>0&&check(i,j,'C')) s[i][j]='C',c--;
else if(d>0&&check(i,j,'D')) s[i][j]='D',d--;
}
}
for(int i=26;i<=n;i++)
{
for(int j=1;j<=n;j+=2)
{
if(a>0&&check(i,j,'A')) s[i][j]='A',a--;
else if(c>0&&check(i,j,'C')) s[i][j]='C',c--;
else if(d>0&&check(i,j,'D')) s[i][j]='D',d--;
}
}
cout<<50<<" 50\n";
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)cout<<s[i][j];
cout<<endl;
}
return 0;
}