/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 1ms 196.0 KiB
#2 Accepted 1ms 208.0 KiB
#3 Accepted 1ms 204.0 KiB
#4 Accepted 1ms 212.0 KiB
#5 Accepted 1ms 208.0 KiB
#6 Accepted 1ms 212.0 KiB
#7 Accepted 6ms 208.0 KiB
#8 Accepted 6ms 200.0 KiB
#9 Accepted 6ms 308.0 KiB
#10 Accepted 6ms 204.0 KiB

代码

#include<bits/stdc++.h>
#define fre(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout)
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x,y,ans=0;
		scanf("%d%d",&x,&y);
		int depx=log2(x)+1,depy=log2(y)+1;
		if(depx<depy) swap(x,y),swap(depx,depy);
//		printf("x:%d y:%d\n",x,y);
		for(int j=depy;j<depx;j++) 
		{
			x/=2,ans++;
//			printf("x:%d y:%d\n",x,y);
		}
		for(int j=log2(y);j>=1;j--)
		{
			if(x==y) break;
			x/=2;
			y/=2;
			ans+=2;
//			printf("x:%d y:%d\n",x,y);
		}
		printf("%d\n",ans);
	}
	return 0;
}

信息

递交者
类型
递交
题目
三向城T1
题目数据
下载
语言
C++
递交时间
2019-12-13 15:22:49
评测时间
2019-12-13 15:22:49
评测机
分数
100
总耗时
34ms
峰值内存
308.0 KiB