当前位置:网站首页>Acwing winter vacation daily question 2022 punch in day 11
Acwing winter vacation daily question 2022 punch in day 11
2022-06-30 05:37:00 【Mechanical endurance】
Original link :
Ideas :
State compression + Looking for a ring , Keep enumerating the next state , Then save the number of steps in each state , If there is a repetition, it means there is a ring , Be sure to add the number of steps from the starting point to the ring , This question is mainly about training state compression , See code for details
Code:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e7+10;
int p[N];
long long n,k;
int get(int now)
{
int res=0;
for(int i=0;i<n;i++)// Simulate the change operation according to the meaning of the topic
{
int j=i-1;
if(j==-1) j=n-1;
int x=now>>i&1,y=now>>j&1;
res|=(x^y)<<i;
}
return res;
}
void print(int x)
{
for(int i=0;i<n;i++)
cout<<(x>>i&1)<<endl;
}
int main()
{
cin>>n>>k;
int star=0;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
star|=x<<i;
}
memset(p,-1,sizeof p);
p[star]=0;
int now=star;
int t=0;
for(int i=1;;i++)
{
now=get(now);
if(i==k)
{
print(now);
break;
}
if(p[now]!=-1)
{
t=i-p[now];
for(int j=0;j<(k-i)%t;j++) now=get(now);// The number of steps left
print(now);
break;
}
else
p[now]=i;
}
return 0;
}
author : Mechanical endurance
link :https://www.acwing.com/activity/content/code/content/2421483/
source :AcWing
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
边栏推荐
- Visualization of 3D geological model based on borehole data by map flapping software
- PKCs 12:personal information exchange syntax v1.1 translation part I
- Question mark (?) in Cron expression Use of
- 领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!
- [chestnut sugar GIS] global mapper - how to assign the elevation value of the grid to the point
- [typescript] defines the return value type of promise
- 遥感图像/UDA:Curriculum-Style Local-to-Global Adaptation for Cross-Domain Remote Sensing Image Segmentat
- Revit二次開發---未打開項目使用面板功能
- Bev instance prediction based on monocular camera (iccv 2021)
- uboot通过终端发送‘r‘字符读取ddr内存大小
猜你喜欢
![[notes] unity webgl input Chinese](/img/f7/805f510ff691227b4c2b529cc1099a.jpg)
[notes] unity webgl input Chinese

How to create a CSR (certificate signing request) file?

What kind of answer has Inspur given in the big AI model landing test?

Unity- the camera follows the player

Digital signature——

What are membrane stress and membrane strain

We strongly recommend more than a dozen necessary plug-ins for idea development

OpenCL线程代数库ViennaCL的使用

86. separate linked list

Database SQL language 04 subquery and grouping function
随机推荐
领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!
抓取手机端变体组合思路设想
14x1.5cm竖向标签有点难,VFP调用BarTender来打印
Detailed explanation of issues related to SSL certificate renewal
OpenCL线程代数库ViennaCL的使用
炒股用指南针开户交易安全吗?
Digital signature——
《谁动了我的奶酪》读后感
Unity determines whether the UI is clicked
Learning about functions QAQ
Revit secondary development - use panel function without opening the project
Baiwen.com 7 days Internet of things smart home learning experience punch in the third day
Unity Catmull ROM curve
[typescript] experimentaldecorators of vscode stepping pit
Rotating frame target detection mmrotate v0.3.1 training dota data set (II)
Unity mobile end sliding screen rotation
Sound net, debout dans le "sol" de l'IOT
网络变压器怎么判断好坏?网络滤波变压器坏了一般是什么症状?
The fourth day of learning C language for Asian people
Did you know that WPS can turn on eye protection mode?