当前位置:网站首页>Exercise 23, pilot brothers [binary enumeration / bit operation]
Exercise 23, pilot brothers [binary enumeration / bit operation]
2022-04-22 03:12:00 【ILECY】
116. Pilot brother - AcWing Question bank
“ Pilot brother ” This game , Need the player to open a possession smoothly 16 A fridge with a handle .
It is known that each handle can be in one of the following two states : Turn on or off .
Only when all the handles are open , The refrigerator will open .
The handle can be expressed as a 4×4 Matrix , You can change any position [i,j] Status of upper handle .
however , This will also make the i Xing He j The status of all the handles on the column also changes .
Please find out the minimum number of switching handles needed to open the refrigerator .
Input format
The input consists of four lines , Each line contains the initial state of four handles .
Symbol + Indicates that the handle is closed , And symbols - Indicates that the handle is open .
The initial state of at least one handle is off .
Output format
The first line outputs an integer N, Indicates the minimum number of switching handles required .
Next N Line description switching order , Output two integers per line , The row number and column number of the handle representing the switched state , The numbers are separated by spaces .
Be careful : If there are many ways to open the refrigerator , Then according to the overall priority from top to bottom , Open from left to right .
Data range
1≤i,j≤4
sample input :
-+--
----
----
-+--
sample output :
6
1 1
1 3
1 4
4 1
4 3
4 4
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define pb push_back
int mp[20][20],add,mm[20][20];
void turn(int tp[20][20],int i,int j){ // change i That's ok j The switch state of the handle on the column
for(int k=1;k<=4;k++){
tp[i][k]=!tp[i][k];
tp[k][j]=!tp[k][j];
}
tp[i][j]=!tp[i][j];
}
int main(){
for(int i=1;i<=4;i++)
for(int j=1;j<=4;j++){
char c;
cin >> c;
if(c=='+') mp[i][j]=0;
else mp[i][j]=1;
}
for(int i=1;i<(1<<16);i++){ //1<<n Express 2 Of n Power , Here is the binary enumeration
int tp[20][20];
memset(mm,0,sizeof(mm));
for(int j=1;j<=4;j++)
for(int k=1;k<=4;k++) tp[j][k]=mp[j][k];
int x=1,y=0;
add=0;
for(int j=0;j<16;j++){
y++;
if(y==5){x++; y=1;}
if(i>>j&1){ //i>>j&1 Judge binary i Of the j Whether a is 1
mm[x][y]=1; // Record
add++;
turn(tp,x,y);
}
}
int flag=0;
for(int j=1;j<=4;j++)
for(int k=1;k<=4;k++)
if(tp[j][k]==0) flag=1;
if(flag==0){
cout << add << endl;
for(int j=1;j<=4;j++)
for(int k=1;k<=4;k++) {
if(mm[j][k]==1) printf("%d %d\n",j,k);
}
return 0;
}
}
return 0;
}
版权声明
本文为[ILECY]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220310573723.html
边栏推荐
- Or1k startup file analysis
- 二十五.模块/内置模块/模块的安装
- 网络和多媒体知识(3)
- Decomposing temporary variables in code refactoring
- C language curriculum design -- examination room ranking system based on linked list
- 500错误,提交响应后无法转发
- Ros2 learning notes (6) -- customized messages and services, control instruction optimization and online map change
- The traffic lights made by enumeration have an interface
- Code refactoring removes the assignment of parameters
- 剑指offer 专项突破版 92、翻转字符
猜你喜欢

ESP32_ GPIO input, output and interrupt

golang依赖注入wire使用 执行wire命令时报错:bash: wire: command not found

Protocole d'authentification Kerberos

Use xamarin to write a beautiful app login and registration interface

【今晚七点】metaRTC的发展和应用场景探讨

全网最全量化硬件设施比拼大会

How did opensea become the most popular NFT market?

The original test engineers who were promoted and raised were good at interface testing

Programmers want to take root in Shenzhen. In addition to Tencent, they can also consider these companies

First glimpse of the pytest framework, weak foundation can easily hold
随机推荐
支付宝H5页面支付
【Laravel系列4.7】连接redis以及缓存应用
Sword finger offer special breakthrough version 93, longest Fibonacci series
2022-4-21作业
Driverless virtual simulation (13) -- traffic sign recognition in image processing 1
Development details of swap exchange arbitrage clip robot system
剑指offer 专项突破版 91、粉刷房子
twenty-eight. Built in module
嘉戎技术深交所上市破发:公司市值41亿 应收账款2.8亿
Stackoverflow:IActionContextAccessor Is Null
Jiarong Technology Shenzhen Stock Exchange listed and discovered: The Value of Market of the company is 4.1 billion, and the Accounts receivables are 280 million.
go语言实战-----31-----流媒体架构设计之直播架构、音视频通话(常见 流媒体协议 解释)
剑指offer 专项突破版 92、翻转字符
Using pytest to play with data-driven testing framework
Super practical chrome plug-in
Analysis of five data structures of redis
终于看清阿里,美团,京东这些企业的真面目了
Driverless virtual simulation (14) -- traffic sign recognition in image processing 2
二十七.包(import)
What others write is called a blog, and what they write is called notes