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≤iN−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 o and x.

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 S and W.
  • If ti is S, it indicates that the animal numbered i is a sheep. If ti is W, 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

Sample Output 3

SSWWSSSWWS

题目链接:http://arc069.contest.atcoder.jp/tasks/arc069_b

题意:n只动物从1到n围成一个圈,每只动物要么是羊要么是狼。每只动物会说出一个字母,说'o'表示它两边动物种类相同,说'x'表示不同。但羊是说真话,狼是说反话。求出这n只动物的种类。
分析:模拟一下就可以了,不过这个模拟比较大!
下面给出AC代码:
 #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的更多相关文章

  1. AtCoder Regular Contest 069 F Flags 二分,2-sat,线段树优化建图

    AtCoder Regular Contest 069 F Flags 二分,2-sat,线段树优化建图 链接 AtCoder 大意 在数轴上放上n个点,点i可能的位置有\(x_i\)或者\(y_i\ ...

  2. AtCoder Regular Contest 069 D - Menagerie 枚举起点 模拟递推

    arc069.contest.atcoder.jp/tasks/arc069_b 题意:一堆不明身份的动物排成一圈,身份可能是羊或狼,羊一定说实话,狼一定说假话.大家各自报自己的两边是同类还是不同类, ...

  3. AtCoder Regular Contest 069 F - Flags

    题意: 有n个点需要摆在一个数轴上,每个点需要摆在ai这个位置或者bi上,问怎么摆能使数轴上相邻两个点之间的距离的最小值最大. 二分答案后显然是个2-sat判定问题,因为边很多而连边的又是一个区间,所 ...

  4. AtCoder Regular Contest 069

    1. C - Scc Puzzle 计算scc的个数,先判断s个数需要多少个cc,多的cc,每四个可以组成一个scc.注意数据范围,使用long long. #include<bits/stdc ...

  5. AtCoder Regular Contest 061

    AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...

  6. AtCoder Regular Contest 094 (ARC094) CDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...

  7. AtCoder Regular Contest 092

    AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...

  8. AtCoder Regular Contest 093

    AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...

  9. AtCoder Regular Contest 094

    AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...

随机推荐

  1. 【CSS3】浏览器内核、私有前缀

    浏览器内核 私有前缀 浏览器 webkit -webkit- chrome.safari.安卓.ios trident -ms- IE gecko -moz- firefox presto -o- o ...

  2. 数据分析与展示——Matplotlib库入门

    Matplotlib库入门 Matplotlib库介绍 Matliotlib库是Python优秀的数据可视化第三方库. Matliotlib库的效果见:http://matplotlib.org/ga ...

  3. UILabletext去掉乱码 控制颜色 行高 自定义大小 。显示不同的字体颜色、字体大小、行间距、首行缩进、下划线等属性(NSMutableAttributedString)

    text去掉乱码 设置不同颜色 行高 自定义大小 #import <Foundation/Foundation.h> @interface TextsForRow : NSObject @ ...

  4. 【算法】论平衡二叉树(AVL)的正确种植方法

    参考资料 <算法(java)>                           — — Robert Sedgewick, Kevin Wayne <数据结构>       ...

  5. INITTAB 配置文件

    Inittab 文件详解       init的进程号是1(ps -aux | less),从这一点就能看出,init进程是系统所有进程的起点,Linux在完成核内引导以后,就开始运行init程序. ...

  6. 使用MethodType函数将方法绑定到类或实例上

    在开始正文之前,需要了解下Python的绑定方法(bound method)和非绑定方法. 简单做个测试: 定义一个类,类中由实例方法.静态方法和类方法. class ClassA: def inst ...

  7. JAVA类的创建: 创建JAVA的类 ,JAVA的字段,JAVA类的方法

    1. 创建Java的类 如果说Java的一切都是对象,那么类型就是决定了某一类对象的外观与行为.可是类型的关键字不是type,而是class,创建一个新的类型要用下面的代码: 1 2 3 class ...

  8. python3之运算符

    1.python算术运算符 >>> a=15 >>> b=5 >>> a+b #加 20 >>> a-b #减 10 >& ...

  9. div外观例子

    title: div外观例子 date: 2018-1-15 14:00:00 tags: 前端 div css categories: 前端框架 --- 标题 我的标题 内容 Font Awesom ...

  10. 简单的vuex 的使用

    1. npm install vuex 2. 在src 下 新建文件夹 store (为什么是这个单词,vuex 是用来状态管理的,用储存一些组件的状态,取存贮之意),store 文件下 新建文件 i ...