栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

CF. Reverse (string,广搜)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CF. Reverse (string,广搜)

Problem - 1618F - Codeforces

x转二进制 每次末尾加‘0’反转或末尾加‘1’ 反转看能不能转化成y

#include
#include
#include
#include
#include
#define lowbit(x) (x&-x)
#define int long long
using namespace std;
const int N=1e5;
typedef pairPII;
int m,n;

string get(int x)
{
	string s="";
	while(x)
	{
		s+=(x%2+'0');
		x/=2;
	}
	reverse(s.begin(),s.end());
	return s;
}
string work(string s)
{
	while(s.back()=='0') s.pop_back();
	reverse(s.begin(),s.end());
	return s;
}
int dd(int x,int y)
{
	queue que;
	map 	book;
	que.push(get(x));
	auto Y=get(y);
	book[get(x)]=1;
	while(!que.empty())
	{
		string t=que.front();
		que.pop();
		if(t.length()>70) continue;
		for(char i='0'; i<='1'; i++)
		{
			string s=work(t+i);
			if(book[s]) continue;
			if(s==Y) return 1;
			book[s]=1;
			que.push(s);
		}
	}
	return x==y;
}
signed main()
{
	int i,j,x,y;
	cin>> x>> y;
	if(dd(x,y)) printf("YESn");
	else printf("NOn");
	return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/664658.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号