/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 3ms 256.0 KiB
#2 Accepted 3ms 256.0 KiB
#3 Accepted 3ms 256.0 KiB
#4 Accepted 4ms 256.0 KiB
#5 Accepted 3ms 384.0 KiB
#6 Accepted 3ms 216.0 KiB
#7 Accepted 18ms 256.0 KiB
#8 Accepted 19ms 356.0 KiB
#9 Accepted 21ms 364.0 KiB
#10 Accepted 22ms 364.0 KiB

代码

#include<bits/stdc++.h>
using namespace std;
int n;
inline const void read(int &a)
{
	a=0;
	char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
}
int work(int x,int y)
{
	int ans=0,k1[40],k2[40];
	memset(k1,0,sizeof(k1));
	memset(k2,0,sizeof(k2));
	while(x)
	{
		k1[++k1[0]]=x%2;
		x/=2;
	}
	while(y)
	{
		k2[++k2[0]]=y%2;
		y/=2;
	}
	if(k1[0]==k2[0]) ans=0;
	else if(k1[0]>k2[0])
	ans=k1[0]-k2[0];
	else ans=k2[0]-k1[0];
	int k3=k1[0],k4=k2[0],k=min(k1[0],k2[0]),t=0;
	while(k3&&k4)	
	{
		if(k1[k3]==k2[k4])
		{
			k3--;
			k4--;
			t++;
		}
		else break;
	}
	return ans+(k-t)*2;
}
int main()
{
	//freopen("city.in.txt","r",stdin);
	//freopen("city.out.txt","w",stdout);
	int x1,x2;
	read(n);
	for(int i=1;i<=n;i++)
	{
		read(x1);
		read(x2);
		if(x1==x2)
		cout<<0<<endl;
		else
		{
			int ans=work(x1,x2);
			cout<<ans<<endl;
		}
	}
	return 0;
}

信息

递交者
类型
递交
题目
三向城T1
题目数据
下载
语言
C++
递交时间
2017-11-07 16:14:05
评测时间
2017-11-07 16:14:05
评测机
分数
100
总耗时
104ms
峰值内存
384.0 KiB