日韩性视频-久久久蜜桃-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)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 久久伊人影院 | 日韩欧美国产激情 | 最近中文字幕第一页 | 日韩精品一区在线播放 | 黄色日批视频 | 欧美日韩在线免费播放 | 污网在线观看 | 欧美日韩中文一区 | 日韩深夜视频 | 亚洲一区在线播放 | 国产欧美久久久久久 | 五十路息子 | 中文字幕在线观看免费 | 自偷自拍亚洲 | 一区二区福利电影 | 手机av观看 | 韩国中文字幕在线观看 | 久久精品视频国产 | 欧美日本一道 | 亚洲av片在线观看 | 91超碰在 | 91在线看| av网址网站 | 日韩九九九 | 亚欧三级| 国产精品久久久网站 | 亚洲精品一区二区三区新线路 | 每日更新av | 国产你懂得| 国产经典三级在线 | 免费啪啪网址 | 长篇高h肉爽文丝袜 | 伊人久久综合影院 | 韩国久久久久 | 成人网一区 | 男人插入女人阴道视频 | 日韩av网页 | 国产激情久久久久 | 毛片成人| 国产精品专区在线观看 | 性xxxx欧美老肥妇牲乱 | 在线免费黄色av | 黄色一级大片免费版 | 亚洲一区二区三区视频在线 | 久久av秘一区二区三区 | 蜜臀久久99精品久久久画质超高清 | 亚洲码国产精品高潮在线 | 中文字幕 国产精品 | 日韩精品影视 | 精品人妻一区二区三区换脸明星 | 婚后打屁股高h1v1调教 | 国产一线在线观看 | 超碰免费人人 | 东北少妇bbbb搡bbb搡 | 精彩毛片 | 91美女视频 | 一级国产片 | 天天干干干 | 成人av一区二区三区在线观看 | 男男做性免费视频网 | 最新99热| 国产大片一区二区 | 丰满大乳国产精品 | 亚洲综合五月天 | sm捆绑调教视频 | 不卡的在线视频 | 国产精品18久久久久久无码 | 黄网在线免费观看 | 伊人网综合视频 | 欧美成人免费大片 | 亚洲欧美伦理 | 精品人妻一区二区免费 | 在线观看av国产一区二区 | 欧美亚洲精品天堂 | 青青草视频黄 | 亚洲欧美日本在线观看 | 一级片亚洲 | 欧美一级片在线播放 | 色爱色| 草草在线影院 | 欧州一区二区三区 | 午夜性激情 | 欧美一区二区三区在线 | 裸体女视频 | 农民工hdxxxx性中国 | www.四虎.com| 青青草原伊人 | 99reav| 九九热超碰| 欧美日韩精品一区二区三区蜜桃 | 免费观看黄色小视频 | 日韩有码第一页 | 亚洲国产精品视频一区 | 国内精品视频一区二区三区 | 欧美视频直播网站 | 亚洲成年网| 欧美在线视频一区二区三区 | 午夜在线不卡 | 美女狂揉羞羞的视频 |