日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Menagerie(AtCoder-2234)

發布時間:2025/3/17 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Menagerie(AtCoder-2234) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem Description

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?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.

Example

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

題意:n 只動物排成一個環,其中有若干只羊和若干只狼,現在從第一個動物開始詢問,問其相鄰的兩動物是否為同一物種。對于羊來說,若是同一物種則說 o,若不是則說 x;對于狼來說,若是同一物種則說 x,若不是則說 o。根據給出的 n 個 o、x 序列,問是否有一種可分配的合法方案,若有則從 1 號輸出到 n 號,其中,羊為 S,狼為 W,若沒有則輸出 -1

思路:

根據題意可知,如果確定了前兩個動物的種類即可確定出 n 個動物的種類,那么總共有 4 種情況:羊羊、羊狼、狼狼、狼羊

因此,從第 2 個開始枚舉到 n-1,根據第 i 個動物的詢問(str[i])與第 i 個動物的狀態(res[i]),即可確定出下一個動物的狀態,從而得出 1~n 的動物狀態

由于這樣枚舉而出的狀態無法確定是否合法,因此我們可以根據第 1、2 個動物的詢問與狀態確定出最后一個動物的狀態(存進 endd 中),再從第 2 個枚舉到 n,根據 n 和 n-1 確定出第一個動物的狀態(存進 res[n-1] 中),然后進行判斷

如果根據枚舉推出的最后一個動物的狀態(res[n])與根據第 1、2 個得出的最后一個動物的狀態(endd)相同,且枚舉推出的第一個動物的狀態(res[n+1])與第一個的動物狀態(res[1])相同,那么說明該種情況最初的假設成立,直接輸出即可

反正,如果以上兩個條件任意一個不滿足,那么說明該種情況最初的假設不成立,枚舉下一種情況,如果 4 種情況都不成立,則說明沒有符合條件分配方案,輸出 -1

Source Program

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long const int MOD = 1E9+7; const int N = 100000+5; const int dx[] = {0,0,-1,1,-1,-1,1,1}; const int dy[] = {-1,1,0,0,-1,1,-1,1}; using namespace std; char str[N]; int res[N]; void cal(int i){if(str[i]=='o'&&res[i]==0){res[i+1]=res[i-1];}else if(str[i]=='o'&&res[i]==1){res[i+1]=!res[i-1];}else if(str[i]=='x'&&res[i]==0){res[i+1]=!res[i-1];}else if(str[i]=='x'&&res[i]==1){res[i+1]=res[i-1];} } int main(){int n;scanf("%d",&n);scanf("%s",str+1);int endd;bool flag=false;res[1]=0;res[2]=0;if(str[1]=='o')endd=0;elseendd=1;for(int i=2;i<=n;i++)cal(i);if(res[n]==endd&&res[1]==res[n+1])flag=true;if(!flag){res[1]=0;res[2]=1;if(str[1]=='o')endd=1;elseendd=0;for(int i=2;i<=n;i++)cal(i);if(res[n]==endd&&res[1]==res[n+1])flag=true;}if(!flag){res[1]=1;res[2]=0;if(str[1]=='o')endd=1;elseendd=0;for(int i=2;i<=n;i++)cal(i);if(res[n]==endd&&res[1]==res[n+1])flag=true;}if(!flag){res[1]=1;res[2]=1;if(str[1]=='o')endd=0;elseendd=1;for(int i=2;i<=n;i++)cal(i);if(res[n]==endd&&res[1]==res[n+1])flag=true;}if(!flag)printf("-1\n");else{for(int i=1;i<=n;i++){if(res[i]==0)printf("S");elseprintf("W");}printf("\n");}return 0; }

?

總結

以上是生活随笔為你收集整理的Menagerie(AtCoder-2234)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产精品视频免费在线观看 | 国产精品36p| 3d动漫啪啪精品一区二区中文字幕 | 国产视频精品一区二区三区 | 国产精品天美传媒 | 逼特逼在线视频 | 免费污视频 | 综合在线亚洲 | 超碰1997| 少妇被躁爽到高潮无码人狍大战 | 色网站免费看 | 日本va在线观看 | 亚洲天堂色 | 国产九九在线 | 欧美性潮喷xxxxx免费视频看 | 人人澡人人干 | 男女无套免费视频网站动漫 | 钻石午夜影院 | 特种兵之深入敌后 | 国产乱人乱偷精品视频a人人澡 | 国产伦精品一区二区 | 成人国产精品久久久 | 中文字幕精品一二三四五六七八 | 精品国产乱码久久久久久闺蜜 | 国产精品午夜视频 | 国产人妻大战黑人20p | 8x8ⅹ国产精品一区二区二区 | 天天综合中文字幕 | 久久美利坚| 国产另类精品 | 青青伊人网| 黄网站免费大全入口 | 欧美狠狠爱| 久久少妇网 | 欧美激情一二三区 | 日本成人免费在线视频 | 日本捏奶吃奶的视频 | 欧美日韩国产一区二区在线观看 | 中文字幕在线观看线人 | 亚洲射 | 两性视频久久 | 亚洲AV无码一区二区三区少妇 | 瑟瑟视频在线 | 色桃av| 成年人爱爱视频 | 天天色天天 | 亚洲熟乱 | 亚洲性天堂 | 国产精品一级黄色片 | 亚洲精品国产成人久久av盗摄 | 黄色网址大全免费 | 91国内在线视频 | 人妻大战黑人白浆狂泄 | 国产在线一二三区 | 亚洲一区二区观看 | 狠狠综合 | 国产山村乱淫老妇女视频 | 日本高清视频一区二区三区 | 国产九九九 | 人人插人人插 | 超碰97人 | 中文字幕韩日 | 五月天一区二区 | 99黄色 | 亚洲每日更新 | 伊人动漫| 久久久久久亚洲中文字幕无码 | 老司机午夜免费视频 | 带aaa级的网名 | 国产精品国产三级国产 | 99精品一区 | 成人在线你懂的 | 午夜在线观看视频18 | 6699av | 另类ts人妖一区二区三区 | 椎名由奈av一区二区三区 | 调教一区二区三区 | 最新av中文字幕 | 自拍偷拍激情小说 | 国产精品99久久久久久久久久久久 | 亚洲熟妇一区二区三区 | 久久九九视频 | 美足av电影 | 男男play呻吟动漫网站 | 美女精品一区二区 | 国产尤物精品 | 欧美久久久 | 婷婷亚洲综合五月天小说 | 亚洲av成人一区二区 | 精品少妇白浆小泬60P | 肥臀熟女一区二区三区 | 日本网站在线看 | 成人免费福利视频 | ,亚洲人成毛片在线播放 | 国产原创视频在线 | 在线观看a级片 | 欧美三级韩国三级日本三斤 | 中文字幕av免费在线观看 | 国产欧美熟妇另类久久久 |