当前位置:网站首页>Luogu 1146 coin flip
Luogu 1146 coin flip
2022-06-26 09:58:00 【yuyanggo】
Title Description
There is a row of coins on the table , common NN gold , Each coin is facing up . Now turn all the coins upside down , The rule is that you can flip any... At a time N-1N−1 Coin ( Turned upside down to upside down , vice versa ). Find the shortest sequence of operations ( Flip each time N-1 A coin becomes an operation ).
Input format
A natural number NN(NN Is not greater than 100100 An even number of ).
Output format
The first line contains an integer SS, Indicates the minimum number of operations required . Next SS Each line represents the status of coins on the table after each operation ( One line contains NN It's an integer (00 or 11), Indicates the status of each coin :00―― face up , and 11―― Reverse up , Extra spaces are not allowed ).
In case of multiple operation schemes , Then only the dictionary order of the operation needs to be the smallest output .
notes : Dictionary order of operations : For one operation ,1 It means flip ,0 Indicates no inversion .
But what you need to output is the status of each operation ,0 Face up ,1 The opposite side is up .
I/o sample
Input #1 Copy
4
Output #1 Copy
4 0111 1100 0001 1111
Topic link :https://www.luogu.com.cn/problem/P1146
Their thinking :
Every time I turn n-1 A coin , Equivalent to turning one at a time , So a total of n Time .
Clearly stated in the title n For the even , So that is to say, if each coin turns n-1 Time , It is equivalent to turning every coin once , So the plan to flip a coin is : Select each coin , Turn over other coins except this one .
Code :
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main() {
int n;
scanf("%d", &n);
printf("%d\n", n);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= i; j++) printf("%d", (i-1)&1);
for(int j = i + 1; j <= n; j++) printf("%d", i&1);
printf("\n");
}
return 0;
}
边栏推荐
- Several connection query methods of SQL (internal connection, external connection, full connection and joint query)
- npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.npm ER
- Threadmode interpretation of eventbus
- thinkphp6.0的第三方扩展包,支持上传阿里云,七牛云
- install realsense2: The following packages have unmet dependencies: libgtk-3-dev
- Download MySQL database installation package website of each system and version
- 我在中山,到哪里开户比较好?在线开户安全么?
- What is the web SSH service port of wgcloud
- Automated testing -- Introduction and example of pytest framework
- Internationalization configuration
猜你喜欢
随机推荐
Go learning notes (83) - code specification and common development skills
LeetCode 基本计算器 224. 227. follow up 394
The basis of C language grammar -- function definition learning
druid数据源实现后台监控
LeetCode 剑指 Offer II 091.粉刷房子 - 原地修改
SQL advanced tutorial
我在中山,到哪里开户比较好?在线开户安全么?
爬虫相关文章收藏:pyppeteer 、Burpsuite
Redis notes (16) - info instructions and command line tools (view memory, status, number of client connections, monitoring server, scan large keys, sampling server, execute batch commands, etc.)
存储过程测试入门案例
Redis notes (15) - Pipeline (the client packages and sends batch commands to save network overhead)
In the fragment, the input method is hidden after clicking the confirm cancel button in the alertdialog (this is valid after looking for it on the Internet for a long time)
halcon 光度立体
Openxcap usage
Differences between VI and vim and common commands
From TF 1 X to TF 2.6 (update if you encounter it)
The 100000 line transaction lock has opened your eyes.
Automated testing -- Introduction and example of pytest framework
Several connection query methods of SQL (internal connection, external connection, full connection and joint query)
This new change of go 1.16 needs to be adapted: the changes of go get and go install









