当前位置:网站首页>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 .
边栏推荐
- pytorch中常用损失函数总结
- You don't know how to deduce the location where HashSet stores elements?
- 网络变压器怎么判断好坏?网络滤波变压器坏了一般是什么症状?
- C # uses monopinvokecallback to directly call back C # function
- UML tools
- PyGame. Why can't I exit when I click X in the window? I can only exit when I return idle
- Revit secondary development - use panel function without opening the project
- Responsive flow layout
- Leader: who can use redis expired monitoring to close orders and get out of here!
- 旋转框目标检测mmrotate v0.3.1 训练DOTA数据集(二)
猜你喜欢

Database SQL language 04 subquery and grouping function

2022年,谁在推动音视频产业的新拐点?

mmcv常用API介绍

RedisTemplate 常用方法汇总

86. separate linked list
![[note] usage model tree of the unity resource tree structure virtualizingtreeview](/img/3e/fe5610c797a14554ad735172c3ab54.jpg)
[note] usage model tree of the unity resource tree structure virtualizingtreeview

How to judge the quality of network transformer? What symptom is network filter transformer broken?

Virtual and pure virtual destructions

旋转框目标检测mmrotate v0.3.1 训练DOTA数据集(二)
![[notes] unity webgl input Chinese](/img/f7/805f510ff691227b4c2b529cc1099a.jpg)
[notes] unity webgl input Chinese
随机推荐
Set of XXL job principles
token 过期后,如何自动续期?
Display steerable 3D model in front of unity UI
On line assignment of financial cost management in the 22nd spring of Western Polytechnic University [Full Score answer]
Codeforces Round #390 (Div. 2) D. Fedor and coupons
pytorch中常用损失函数总结
What kind of answer has Inspur given in the big AI model landing test?
AI大模型落地大考,浪潮交出了怎样的答卷?
VFPBS上传EXCEL并保存MSSQL到数据库中
Online assignment of C language program design in the 22nd spring of Western Polytechnic University
抓取手机端变体组合思路设想
Solidity - Security - reentrancy attack
Database SQL language 05 SQL exercise
如何写论文
Operation of JSON file
聲網,站在物聯網的“土壤”裏
剑指 Offer 18. 删除链表的节点
[typescript] experimentaldecorators of vscode stepping pit
English语法_形容词/副词3级-最高级
Unity determines whether the UI is clicked