码迷,mamicode.com
首页 > 其他好文 > 详细

UVALive - 6809 Spokes Wheel(位运算)

时间:2015-04-24 09:03:57      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

题目链接

https://icpcarchive.ecs.baylor.edu/external/68/6809.pdf

枚举可以过,但弄个字符串或者数组去处理进制转换的确很麻烦,在vj里找到个大神的代码,真tm神奇,在这里贴下。

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
	unsigned int A, B;
	unsigned int a, b;
	int casen;
	cin >> casen;
	for (int cas = 1; cas <= casen;cas++)
	{
		scanf("%x%x", &A, &B);
		int r=0, l=0;
		a = A, b = B;
		while (a != b&&l<32){
			a = (a >> 31) | (a << 1);
			l++;
		}
		a = A, b = B;
		while (a != b&&r<32){
			a = (a << 31) | (a >> 1);
			r++;
		}
		if (l == 32) printf("Case #%d: Not possible\n", cas);
		else if (l == r) printf("Case #%d: %d Any\n", cas, l);
		else if (l<r) printf("Case #%d: %d Left\n", cas, l);
		else printf("Case #%d: %d Right\n", cas, r);
	}
}


UVALive - 6809 Spokes Wheel(位运算)

标签:

原文地址:http://blog.csdn.net/qq_18738333/article/details/45237309

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!