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 ...
随机推荐
- nth-child和nth-of-type的使用案列
HTML: <div id="footer-f"> <ul class="trajectory"> <li> <div ...
- java 使用 POI 操作 XWPFDocumen 创建和读取 Office Word 文档基础篇
注:有不正确的地方还望大神能够指出,抱拳了 老铁! 参考 API:http://poi.apache.org/apidocs/org/apache/poi/xwpf/usermodel/XWPFDoc ...
- 2019-11-12-WPF-添加窗口消息钩子方法
title author date CreateTime categories WPF 添加窗口消息钩子方法 lindexi 2019-11-12 18:46:53 +0800 2019-06-05 ...
- MUI - sortable在mui.js前端框架不兼容的解决方案
关于sortable看这 兼容的解决方案看这 http://www.cnblogs.com/phillyx/ 示例代码已更到github
- 【JZOJ4833】【NOIP2016提高A组集训第3场10.31】Mahjong
题目描述 解法 搜索. 代码 #include<stdio.h> #include<iostream> #include<string.h> #include< ...
- NEFU 118 n!后面有多少个0【数论】
http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=118 求n!后面有多少个0(1<=n<=1000000000) ...
- 部署zabbix3.2.7,升级到3.4、proxy部署
一.Server安装 可以使用mysql.percona.mariadb等,本例使用mariadb.由于是事后整理,只截取部分命令. #yum install mariadb-server maria ...
- iOS 通知观察者的被调函数不一定运行在主线程
Tony in iOS | 08/08/2013 iOS 通知观察者的被调函数不一定运行在主线程 今天修复Bug时候发现的一个小细节,记录下. 问题描述 事情是这样的:我在A视图(UITableVie ...
- 通知: Spring Cloud Alibaba 仓库迁移
最近,Spring Cloud 官方修改了各个第三方项目的发布策略,第三方 spring-cloud 项目需要自身维护.基于此策略,Spring-Cloud-Alibaba 项目迁移到了 alibab ...
- VirtualBox使用随笔
1.virtualbox配置Android手机USB热点 host:Windows10;guest:windows XP/10 右击我的电脑 - 管理 - 设备管理器 - 网卡适配器,若手机正确vb连 ...