当前位置:网站首页>P6183 [USACO10MAR] The Rock Game S
P6183 [USACO10MAR] The Rock Game S
2022-07-05 15:03:00 【A program ape who beats the keyboard violently】
Program ape kills CSDN Force list , ranking 31!!!

P6183 [USACO10MAR] The Rock Game S
# [USACO10MAR] The Rock Game S
## Title Description
Before the cows go home for rest and recreation ,Farmer John I hope they can get some intellectual stimulation by playing games . Game board by $n$ Composed of the same holes , These holes were originally ** Are empty **. A cow either covers a hole with a stone , Or uncover a previously covered hole .** Game status ** The definition of is which holes are covered by stones , Which holes are not covered . The goal of the game is to make the cow accurately reach every possible game state once , Then return to the state that all holes are not covered . Here is an example of one of their games ( Empty holes are used `O` Express , The hole covered with stone is used `X` Express ):
| Time | hole 1 | hole 2 | hole 3 | describe |
| :----------: | :----------: | :----------: | :----------: | :----------: |
| $0$ | O | O | O | At first all the holes were empty |
| $1$ | O | O | X | Cover the hole 3 |
| $2$ | X | O | X | Cover the hole 1 |
| $3$ | X | O | O | Open the hole 3 |
| $4$ | X | X | O | Cover the hole 2 |
| $5$ | O | X | O | Open the hole 1 |
| $6$ | O | X | X | Cover the hole 3 |
| $7$ | X | X | X | Cover the hole 1 |
Now the cow is stuck and can't play anymore ! They have to open a hole , No matter which hole they open , They will all reach the state they have reached . for example , If they take the rock out of the second hole , They will arrive at their time $2$ Status that has been accessed (`X O X`).
Here's a 3 An effective solution for holes :
| Time | hole 1 | hole 2 | hole 3 | describe |
| :----------: | :----------: | :----------: | :----------: | :----------: |
| $0$ | O | O | O | At first all the holes were empty |
| $1$ | O | X | O | Cover the hole 2 |
| $2$ | O | X | X | Cover the hole 3 |
| $3$ | O | O | X | Open the hole 2 |
| $4$ | X | O | X | Cover the hole 1 |
| $5$ | X | X | X | Cover the hole 2 |
| $6$ | X | X | O | Open the hole 3 |
| $7$ | X | O | O | Open the hole 2 |
| $8$ | O | O | O | Open the hole 1, Return to the original state |
Now? , Cows are tired of this game , They want to ask you for help .
Given $n$, Find an effective solution sequence for the game . If there are multiple solutions , Then return to ** Any one **.
## Input format
Just one line , An integer $n$.
## Output format
common $n$ That's ok , One length per line is $n$ String , It contains only characters `O` and `X`, The... In this line $i$ The first character represents the second $i$ Are the holes covered or not covered in this state , The first and last lines must all be `O`.
## Examples #1
### The sample input #1
```
3
```
### Sample output #1
```
OOO
OXO
OXX
OOX
XOX
XXX
XXO
XOO
OOO
```
## Tips
#### Examples 1 explain
See Title Description .
#### Data scale and agreement
about $100\%$ The data of , Yes $1\le n\le15$.
【 Ideas 】
Together, we are very good at thinking challenging The topic , Basically It's direct Set of templates .
【AC Code 】
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e6+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n;
bool flag[N],a[N]={true},b[N][20];
void print()
{
for(int i=1;i<=1<<n;i++)
{
for(int j=1;j<=n;j++)
{
if(b[i][j])cout<<"X";
else cout<<"O";
}
cout<<"\n";
}
}
int check()// Binary to decimal
{
int ans=0;
for(int i=1;i<=n;i++)ans=ans*2+flag[i];// Conversion core
return ans;
}
void dfs(int m)
{
if(m==(1<<n))// After observation , There are several holes 2 Several square steps , That's the basis , Write this if sentence
{
print();
exit(0);
}
for(int i=1;i<=n;i++)
{
flag[i]=!flag[i];// Mark
if(a[check()])// Judge whether you have passed
{
flag[i]=!flag[i];// to flash back
continue;// Just skip
}
a[check()]=true;// Record as walking
for(int j=1;j<=n;j++)b[m][j]=flag[j];// Store answers
dfs(m+1),a[check()]=false,flag[i]=!flag[i];// Continue to search , to flash back
}
}
signed main()
{
n=fread();
for(int i=1;i<=n;i++)cout<<"O";
cout<<"\n";
dfs(1);// Search for
return 0;
}It's a little complicated to use search , See a person who doesn't need dfs Of , But what I practice now is dfs, Let's use it .

边栏推荐
- FR练习题目---简单题
- Leetcode: Shortest Word Distance II
- Cartoon: what are the attributes of a good programmer?
- Jmeter性能测试:ServerAgent资源监控
- Topology visual drawing engine
- MongDB学习笔记
- Magic methods and usage in PHP (PHP interview theory questions)
- Mongdb learning notes
- 华为哈勃化身硬科技IPO收割机
- Does maxcompute have SQL that can query the current storage capacity (KB) of the table?
猜你喜欢

Drive brushless DC motor based on Ti drv10970

Ctfshow web entry information collection

百亿按摩仪蓝海,难出巨头

计算中间件 Apache Linkis参数解读

实现一个博客系统----使用模板引擎技术

There is a powerful and good-looking language bird editor, which is better than typora and developed by Alibaba

Photoshop插件-动作相关概念-ActionList-ActionDescriptor-ActionList-动作执行加载调用删除-PS插件开发

数据库学习——数据库安全性

Dark horse programmer - software testing -10 stage 2-linux and database -44-57 why learn database, description of database classification relational database, description of Navicat operation data, de

Mysql---- function
随机推荐
Cartoon: what are the attributes of a good programmer?
12 MySQL interview questions that you must chew through to enter Alibaba
Crud of MySQL
用 Go 跑的更快:使用 Golang 为机器学习服务
maxcompute有没有能查询 表当前存储容量的大小(kb) 的sql?
Under the crisis of enterprise development, is digital transformation the future savior of enterprises
easyOCR 字符識別
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
长列表优化虚拟滚动
Crud de MySQL
Can I pass the PMP Exam in 20 days?
Coding devsecops helps financial enterprises run out of digital acceleration
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
启牛证券账户怎么开通,开户安全吗?
FR练习题目---简单题
anaconda使用中科大源
Drive brushless DC motor based on Ti drv10970
Implement a blog system -- using template engine technology
可转债打新在哪里操作开户是更安全可靠的呢
Mongdb learning notes