当前位置:网站首页>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 .
边栏推荐
- UML tools
- mmdet之Loss模块详解
- How to judge the quality of network transformer? What symptom is network filter transformer broken?
- 《谁动了我的奶酪》读后感
- 【板栗糖GIS】global mapper—如何把栅格的高程值赋予给点
- 3D rotation album
- Revit secondary development - use panel function without opening the project
- 2022年,谁在推动音视频产业的新拐点?
- 旋转框目标检测mmrotate v0.3.1入门
- OpenCL线程代数库ViennaCL的使用
猜你喜欢

Learning about functions QAQ

Solitidy - fallback 回退函数 - 2种触发执行方式

Solidity - 安全 - 重入攻击(Reentrancy)
![[chestnut sugar GIS] global mapper - how to assign the elevation value of the grid to the point](/img/bb/ea0e78065ba54ff253995faeeb6901.png)
[chestnut sugar GIS] global mapper - how to assign the elevation value of the grid to the point

East Tower attack and defense world - XSS bypasses the safety dog

Unity- the camera follows the player

Redistemplate common method summary

OpenCL线程代数库ViennaCL的使用

Unity publishing /build settings

How to create a CSR (certificate signing request) file?
随机推荐
We strongly recommend more than a dozen necessary plug-ins for idea development
Idea of capturing mobile terminal variant combination
Terminal convenient SSH connection
炒股用指南针开户交易安全吗?
Detailed explanation of issues related to SSL certificate renewal
Assembly learning tutorial: accessing memory (3)
[Blue Bridge Road -- bug free code] DS1302 time module code analysis
How to write a thesis
Solidy - fallback function - 2 trigger execution modes
Wechat applet training 2
/Path/to/ idiom, not a command
pytorch中常用损失函数总结
Database SQL language 06 single line function
Database SQL language 04 subquery and grouping function
How to automatically renew a token after it expires?
RedisTemplate 常用方法汇总
Learning about functions QAQ
Xctf--Web--Challenge--area Wp
Xijiao 21 autumn "motor and drive" online homework answer sheet (III) [standard answer]
Database SQL language 05 SQL exercise