当前位置:网站首页>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;
}
边栏推荐
- DAY 3 数组,前置后置,字符空间,关键词和地址指针
- Testing practice - App testing considerations
- The basis of C language grammar -- function nesting, Fibonacci sum of recursive applet and factorial
- Deep learning (tentsorflow2. version) three good student performance problems (1)
- Enter the page input box to automatically obtain the focus
- How to find and install the dependent libraries of Debian system
- Logview Pro can be used if the log is too large
- LeetCode 0710.黑名单中的随机数 - 预处理实现O(1)取值
- 测试实践——app 测试注意点
- Do you know the //go: instructions in the go source code, go:linkname?
猜你喜欢

MapReduce & yarn theory

Force buckle ----- remove the maximum and minimum values from the array

Record a time when the server was taken to mine

Specific implementation comparison between different programming languages

The 100000 line transaction lock has opened your eyes.

Detailed explanation of the network security competition questions (2) of the 2021 national vocational college skills competition (secondary vocational group)

Deep learning (tentsorflow2. version) three good student performance problems (1)

Druid data source for background monitoring

Install new version cmake & swig & tinyspline

Custom interceptor
随机推荐
Enter the page input box to automatically obtain the focus
同花顺炒股软件安全性怎样?在同花顺怎么开户
The basis of C language grammar -- learning of local variables and storage categories, global variables and storage categories, and macro definitions
国际化配置
Daily-used English phrases
WIN10系统实现Redis主从复制
爬虫相关文章收藏:pyppeteer 、Burpsuite
install opencv-contrib-dev to use aruco code
VI summary of common commands
My creation anniversary
Openxcap usage
LeetCode 剑指 Offer II 091.粉刷房子 - 原地修改
Automated testing -- Introduction and example of pytest framework
Problems encountered by jupyter notebook
Testing practice - App testing considerations
如何更改微信小程序二维码物料颜色
logback
halcon 光度立体
Notes on sports planning on November 22, 2021
测试须知——常见接口协议解析