AtCoder Regular Contest 069 D
D - Menagerie
Time limit : 2sec / Memory limit : 256MB
Score : 500 points
Problem Statement
Snuke, who loves animals, built a zoo.
There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i(2≤i≤N−1) is adjacent to the animals numbered i−1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N−1 and 1.
There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.
Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered si. Here, if si is o, the animal said that the two neighboring animals are of the same species, and if si is x, the animal said that the two neighboring animals are of different species.
More formally, a sheep answered o if the two neighboring animals are both sheep or both wolves, and answered x otherwise. Similarly, a wolf answered x if the two neighboring animals are both sheep or both wolves, and answered o otherwise.
Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print -1.
Constraints
- 3≤N≤105
- s is a string of length N consisting of
oandx.
Input
The input is given from Standard Input in the following format:
N
s
Output
If there does not exist an valid assignment that is consistent with s, print -1. Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s.
- t is a string of length N consisting of
SandW. - If ti is
S, it indicates that the animal numbered i is a sheep. If ti isW, it indicates that the animal numbered i is a wolf.
Sample Input 1
6
ooxoox
Sample Output 1
SSSWWS
For example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.
Let us remind you: if the neiboring animals are of the same species, a sheep answers o and a wolf answers x. If the neiboring animals are of different species, a sheep answers x and a wolf answers o.

Sample Input 2
3
oox
Sample Output 2
-1
Print -1 if there is no valid assignment of species.
Sample Input 3
10
oxooxoxoox
#include <bits/stdc++.h>
using namespace std;
const int N=;
int gh(char *str,char *ch,int n) {
for(int i=; i<n; i++) {
if(i<n-) {
if(str[i]=='o') {
if(ch[i]=='S') {
ch[i+]=ch[i-];
} else {
if(ch[i-]=='S') ch[i+]='W';
else ch[i+]='S';
}
} else {
if(ch[i]=='S') {
if(ch[i-]=='S') ch[i+]='W';
else ch[i+]='S';
} else {
ch[i+]=ch[i-];
}
}
}
else if(i==n-) {
if(str[i]=='o') {
if(ch[i]=='S') {
if(ch[i+]!=ch[i-]) {
return ;
}
}
else {
if(ch[i+]==ch[i-]){
return ;
}
}
}
else{
if(ch[i]=='S'){
if(ch[i+]==ch[i-]){
return ;
}
}
else{
if(ch[i+]!=ch[i-]) {
return ;
}
}
}
}
else if(i==n-){
if(str[i]=='x'){
if(ch[i]=='S') {
if(ch[n-]==ch[]) return ;
}
else{
if(ch[n-]!=ch[]) return ;
}
}
else{
if(ch[i]=='S'){
if(ch[n-]!=ch[]) return ;
}
else{
if(ch[n-]==ch[]) return ;
}
}
}
}
return ;
}
int main() {
char str[N];
char ch[N];
int n;
int flag=;
scanf("%d",&n);
scanf("%s",str);
ch[]='S';
if(str[]=='o') {
memset(ch,,sizeof(ch));
ch[]='S';
ch[]='S';
ch[n-]='S';
flag=gh(str,ch,n);
if(flag==) {
for(int i=; i<n; i++) printf("%c",ch[i]);
puts("");
return ;
} else {
memset(ch,,sizeof(ch));
ch[]='S';
ch[]='W';
ch[n-]='W';
flag=gh(str,ch,n);
if(flag==){
for(int i=;i<n;i++) printf("%c",ch[i]);
puts("");
return ;
}
}
}
else{
memset(ch,,sizeof(ch));
ch[]='S';
ch[]='S';
ch[n-]='W';
flag=gh(str,ch,n);
if(flag==){
for(int i=;i<n;i++) printf("%c",ch[i]);
puts("");
return ;
}
else{
memset(ch,,sizeof(ch));
ch[]='S';
ch[]='W';
ch[n-]='S';
flag=gh(str,ch,n);
if(flag==){
for(int i=;i<n;i++) printf("%c",ch[i]);
puts("");
return ;
}
}
}
ch[]='W';
if(str[]=='o'){
memset(ch,,sizeof(ch));
ch[]='W';
ch[]='S';
ch[n-]='W';
flag=gh(str,ch,n);
if(flag==){
for(int i=;i<n;i++) printf("%c",ch[i]);
puts("");
return ;
}
else{
ch[]='W';
ch[]='W';
ch[n-]='S';
flag=gh(str,ch,n);
if(flag==){
for(int i=;i<n;i++) printf("%c",ch[i]);
puts("");
return ;
}
}
}
else{
memset(ch,,sizeof(ch));
ch[]='W';
ch[]='S';
ch[n-]='S';
flag=gh(str,ch,n);
if(flag==){
for(int i=;i<n;i++) printf("%c",ch[i]);
puts("");
}
else{
ch[]='W';
ch[]='W';
ch[n-]='W';
flag=gh(str,ch,n);
if(flag==){
for(int i=;i<n;i++) printf("%c",ch[i]);
puts("");
return ;
}
}
}
puts("-1");
return ;
}
AtCoder Regular Contest 069 D的更多相关文章
- AtCoder Regular Contest 069 F Flags 二分,2-sat,线段树优化建图
AtCoder Regular Contest 069 F Flags 二分,2-sat,线段树优化建图 链接 AtCoder 大意 在数轴上放上n个点,点i可能的位置有\(x_i\)或者\(y_i\ ...
- AtCoder Regular Contest 069 D - Menagerie 枚举起点 模拟递推
arc069.contest.atcoder.jp/tasks/arc069_b 题意:一堆不明身份的动物排成一圈,身份可能是羊或狼,羊一定说实话,狼一定说假话.大家各自报自己的两边是同类还是不同类, ...
- AtCoder Regular Contest 069 F - Flags
题意: 有n个点需要摆在一个数轴上,每个点需要摆在ai这个位置或者bi上,问怎么摆能使数轴上相邻两个点之间的距离的最小值最大. 二分答案后显然是个2-sat判定问题,因为边很多而连边的又是一个区间,所 ...
- AtCoder Regular Contest 069
1. C - Scc Puzzle 计算scc的个数,先判断s个数需要多少个cc,多的cc,每四个可以组成一个scc.注意数据范围,使用long long. #include<bits/stdc ...
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- AtCoder Regular Contest 094 (ARC094) CDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...
- AtCoder Regular Contest 092
AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...
- AtCoder Regular Contest 093
AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...
- AtCoder Regular Contest 094
AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...
随机推荐
- 如何用VSCode愉快的写Python
在学习Python的过程中,一直没有找到比较趁手的第三方编辑器,用的最多的还是Python自带的编辑器.由于本人用惯了宇宙第一IDE(Visual Studio),所以当Visual Studio C ...
- C++ 头文件系列(stdexcept)
预定义异常类 这个头文件包含的内容非常简单,只包含9个异常类,均从exception类派生,因此我们用三张图来描述: 这里仅解释两点: overflow : 指值的大小超过 整型 变量能表示的范围,即 ...
- Java自己动手写连接池三
Java自己动手写连接池三,核心代码; package com.kama.cn; import java.sql.Connection;import java.util.ArrayList;impor ...
- 微服务架构介绍和RPC框架对比
微服务架构介绍和RPC框架对比 1.微服务架构 1.1 特征 自动化部署,端点智能化,语言和数据的去中心化控制. 1.2架构 一种将一个单一应用程序开发为一组小型服务的方法,每个服务运行在自己的进程中 ...
- php gif处理
http://www.jb51.net/article/51702.htm https://github.com/Sybio/GifCreator https://github.com/Sybio/G ...
- 3D轮播切换特效 源码
这个3D轮播切换特效是我2017年2月份写的 当初我 刚接触HTML不久,现在把源码分享给大家 源码的注释超级清楚 . <!-- 声明文档类型:html 作用:符合w3c统一标准规范 每个浏览器 ...
- Python并发实践_02_通过yield实现协程
python中实现并发的方式有很多种,通过多进程并发可以真正利用多核资源,而多线程并发则实现了进程内资源的共享,然而Python中由于GIL的存在,多线程是没有办法真正实现多核资源的. 对于计算密集型 ...
- Xposed hook布局类资源文件的获取
如题,可以hook状态栏,为系统状态栏添加一个TextView @Override public void handleInitPackageResources(XC_InitPackageResou ...
- 带以太网的MicroPython开发板:TPYBoardv201建立云加法器实例
转载请注明文章来源,MicroPythonQQ技术交流群:157816561,公众号:MicroPython玩家汇 前面的一篇文档向大家介绍了v201的开发板作为客户端终端向TCPS上传数据的基本过程 ...
- Jenkins:基于linux构建ivy项目
Jenkins:基于linux构建ivy项目 (二) 基于以上<Jenkins:VMware虚拟机Linux系统的详细安装和使用教程(一)>的配置再进行对ivy项目构建: 启动tomcat ...