CCPC2018 桂林 D "Bits Reverse"
题目描述
Now given two integers x and y, you can reverse every consecutive three bits in arbitrary number’s binary form (any leading zero can be taken into account) using one coin. Reversing (,,) means changing it into (,,).
Could you please find a way that minimize number of coins so that x = y? If you can, just output the minimum coins you need to use. 输入
The first line of input file contains only one integer T (≤T≤) indicating number of test cases.
Then there are T lines followed, with each line representing one test case.
For each case, there are two integers x, y (≤x,y≤) described above. 输出
Please output T lines exactly.
For each line, output Case d: (d represents the order of the test case) first. Then output the answer in the same line. If there is no way for that, print - instead.
题意描述
样例输入 样例输出
Case : -
Case :
Case :
样例输入输出
题意:
给你两个数 x,y,定义一个操作,可以反转连续的三个位置(转化成二进制后的连续三个位置);
问,最少需要多少操作,可以使得 x == y;
如果不能,输出 -1;
思路:
这题卡了一会,如何快速交换二进制的两个位的值呢?
答案:异或大法好;
假设 x = (100)
定义 t1 = x&1 , t3 = x>>2&1 ;
x ^= (t1^t3);
x ^= (t1^t3)<<2;
本来就不是难题,还是,数据不太给力????????
为啥看了几篇2018CCPC桂林游记,他们的这个题,都wa了好多发呢????
总有种不太靠谱的感觉,可,也找不出错误样例了!!!!
CCPC2018 桂林 D "Bits Reverse"的更多相关文章
- upc组队赛17 Bits Reverse【暴力枚举】
Bits Reverse 题目链接 题目描述 Now given two integers x and y, you can reverse every consecutive three bits ...
- CCPC2018 桂林 G "Greatest Common Divisor"(数学)
UPC备战省赛组队训练赛第十七场 with zyd,mxl G: Greatest Common Divisor 题目描述 There is an array of length n, contain ...
- [LeetCode] Reverse Bits 翻转位
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- Leetcode-190 Reverse Bits
#190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432615 ...
- [leetcode] Reverse Bits
Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...
- leetcode reverse bits python
Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...
- 【LeetCode】190 & 191 - Reverse Bits & Number of 1 Bits
190 - Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432615 ...
- LeetCode 190. Reverse Bits (算32次即可)
题目: 190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432 ...
- [LeetCode] 190. Reverse Bits 颠倒二进制位
Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 ...
随机推荐
- Python之常用模块1
1.time datetime模块 #_*_coding:utf-8_*_ __author__ = 'Alex Li' import time # print(time.clock()) #返回处理 ...
- Spring表达式语言:SpEl
概念: 是一个支持运行时查询和操作的对象图的强大的表达式语言. 语法类似于EL:SpEl使用#{ ...}作为定界符,所有在大括号中的 字符都将被认为是SpEl SpEl为bean的属性进行动态赋值提 ...
- kubernetes1.4新特性:支持两种新的卷插件
背景介绍 在Kubernetes中卷的作用在于提供给POD持久化存储,这些持久化存储可以挂载到POD中的容器上,进而给容器提供持久化存储. 从图中可以看到结构体PodSpec有个属性是Volumes, ...
- prepareStatement设置参数,mysql数据出现中文‘?’的情景与解决方式
在prepareStatement中传入中文的参数,mysql数据库中出现“?”号 try { Class.forName("com.mysql.jdbc.Driver"); co ...
- 让PHP文件每隔几秒执行一次
转自:http://www.blhere.com/966.html 背景是这样的:我需要一段PHP代码去定期对数据库操作,并把结果保存起来.如果方法是用户请求的时候来触发执行这个代码,显然用户的响应时 ...
- HDU-1160_FatMouse's Speed
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Sp ...
- Android7.0 添加快速设定Quick Settings Tile
Android7.0新推出了一个非常实用的功能--添加快速设定(或者翻译成快速设置),但是感觉社区里关注的人比较少,可能目前为止国内还没有Android7.0的手机,但是越早接触越好,甚至可以告诉产品 ...
- 字符串分割+二维数组 Day15练习
package com.sxt.arrays.test; import java.util.Arrays; /* 1,2,3,4!5,6,7!8,9!12,456,90!32 * 将此字符串以叹号为分 ...
- Myeclipse 方法中文注释看不到
参考以下几种解决方式: 1 改变整个文件类型的编码格式 1) eclipse->window->preferences->General->Content Types 2) 找 ...
- Python基础:12函数细节
一:返回值 当没有显式地返回元素时,Python 会返回一个None.如果函数返回多个对象,python 把他们聚集起来并以一个元组返回. 二:创建函数 1:强烈推荐,在函数体之前,编写函数的文档字符 ...