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所属类型
编程语言分类及python所属类型 编程语言主要从以下几个角度为进行分类:编译型和解释型.静态语言和动态语言.强类型定义语言和弱类型定义语言. 编译和解释的区别是什么? 编译器是把源程序的每一条语句都 ...
- 转:国内从事CV相关的企业
http://blog.csdn.net/carson2005/article/details/7356225 经常碰到朋友问我国内从事计算机视觉(CV)领域的公司的发展情况,产品情况,甚至找工作等问 ...
- 利用幂等性区分HTTP的POST与PUT请求
1.什么是幂等性 幂等性概念:幂等通俗来说是指不管进行多少次重复操作,都是实现相同的结果. 2.REST请求中哪些是幂等操作 GET,PUT,DELETE都是幂等操作,而POST不是,以下进行分析: ...
- IntelliJ IDEA 添加项目后编译显示包不存在的解决方案
File -> Project Structure -> Modules 看看是否有多个项目,删掉无用的.或者调整一下项目,重新 Mark as 一下,指定成 Sources
- C++ 引用#include<math.h> 找不到动态库
问题: 使用g++ 编译C++文件报错了,无法识别abs,可是我这文件中已经添加了#include<math.h>? 于是在指令中加入-lm g++ main.cpp AStar.cpp ...
- CDH5.13.1安装
文件下载 Cloudera Manager 地址:http://archive.cloudera.com/cm5/cm/5/ 这里下载的是5.13.1的版本,https://archive.cloud ...
- Oracle基础知识点——Oracle常用权限理解:SYSDBA、SYSOPER、Normal、dba、connect、resource
权限介绍 系统权限 含义:系统规定用户使用数据库的权限,系统权限是针对用户对数据库的操作而言(登录数据库:读取数据表.视图:删除数据库).它只是概念上的role,只是一种登录认证时的身份标识而已. S ...
- 两张图说明http协议,tcp协议,ip协议,dns服务之间的关系和区别
一.理解一个传输流再去扩展 用http举例来说,首先作为发送端的客户端在应用层(http协议)发出一个想看某个web页面的http请求. 接着,为了传输方便,在传输层(tcp协议)把从应用层处收到的数 ...
- postman 百度网盘下载 64位
最近找了一下postman的下载资源,竟然发现有些用户的资源要用csdn的积分下载,很是不爽.所以才想到在这里贴出我的百度网盘的地址 下载地址: 链接:https://pan.baidu.com/s/ ...
- jquery on事件
可以给后添加的动态元素绑定事件