TC SRM 665 DIV2 A LuckyXor 暴力
LuckyXor
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
TC
Description
A lucky number is a positive integer consisting of only the digits 4 and 7.
Given an int a, return an int b strictly greater than a, such that a XOR b is a lucky number. (See Notes for the definition of XOR.) The number b should be in the range 1 to 100, inclusive. If such a number does not exist, return -1. If there are multiple such b, you may return any of them.
XOR is the bitwise exclusive-or operation. To compute the value of P XOR Q, we first write P and Q in binary. Then, each bit of the result is computed by applying XOR to the corresponding bits of the two numbers, using the rules 0 XOR 0 = 0, 0 XOR 1 = 1, 1 XOR 0 = 1, and 1 XOR 1 = 0.
For example, let's compute 21 XOR 6. In binary these two numbers are 10101 and 00110, hence their XOR is 10011 in binary, which is 19 in decimal.
You can read more about the XOR operation here: https://en.wikipedia.org/wiki/Exclusive_or
Input
a is between 1 and 100, inclusive.
Output
int construct(int a)
Sample Input
4
Sample Output
40
HINT
题意
让你找到一个b,使得a^b是幸运数
幸运数指的是只含有4或者7的数
题解:
数据范围只有100,所以直接暴力就好了
代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std; class LuckyXor{
public:
int check(int x)
{ while(x)
{ int X=x%;
if(X==||X==)
x/=;
else
return ; }
return ;
}
int construct(int a){
int ans=-;
for(int i=a+;i<=;i++)
{
int X=(a^i);
if(check(X)==)
{
ans=i;
break;
}
}
return ans;
}
};
TC SRM 665 DIV2 A LuckyXor 暴力的更多相关文章
- TC SRM 665 DIV2 B LuckyCycle 暴力
LuckyCycleTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.ac ...
- TC SRM 663 div2 A ChessFloor 暴力
ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a squa ...
- TC SRM 664 div2 A BearCheats 暴力
BearCheats Problem Statement Limak is an old brown bear. Because of his bad eyesight he sometime ...
- TC SRM 663 div2 B AABB 逆推
AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many En ...
- TC SRM 607 DIV2
求拼接完成后的字符串包含的子回文串的数目,一开始还用暴力去做,想都不用想 肯定超时了. 复习了一下求最长子回文串的算法,发现可以类似解决. 给相邻字符之间添加一个'@'字符,这样所有的回文串都是奇数长 ...
- TC SRM 593 DIV2 1000
很棒的DP,不过没想出,看题解了..思维很重要. #include <iostream> #include <cstdio> #include <cstring> ...
- TC SRM 591 DIV2 1000
很不错的一题,非常巧妙的用DP顺序解决这个问题... 可以发现,只和A里面最小的有关系... #include <cstdio> #include <cstring> #inc ...
- tc srm 636 div2 500
100的数据直接暴力就行,想多了... ac的代码: #include <iostream> #include <cstdio> #include <cstring> ...
- TC SRM 664 div2 B BearPlaysDiv2 bfs
BearPlaysDiv2 Problem Statement Limak is a little bear who loves to play. Today he is playing by ...
随机推荐
- Java中的面向接口编程
面向接口编程是很多软件架构设计理论都倡导的编程方式,学习Java自然少不了这一部分,下面是我在学习过程中整理出来的关于如何在Java中实现面向接口编程的知识.分享出来,有不对之处还请大家指正. 接口体 ...
- linux命令——磁盘管理cd
Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的. cd指令可让用户在不同的目录间切换,但该用户必须拥有足够的权限进入目的目录. 1 ...
- ASP.NET将word文档转换成pdf的代码
一.添加引用 using Microsoft.Office.Interop.Word; 二.转换方法 1.方法 C# 代码 /// <summary> /// 把Word文件转换成pdf文 ...
- python easy_install centos 下安装过程和原理解析
一.easy_install 安装过程 其安装过程有很多种,我也找了很多的例子,但是结果都不太好,以下方法的结果是不错的. easy_install与yum类似,使用easy_install,可以轻松 ...
- redo buffer大小
转载自http://blog.csdn.net/robinson1988/article/details/4729858 log buffer 是SGA中一块循环使用的内存区域,它一般很小,因为有4个 ...
- 使用Google Chart API绘制组合图
Google Chart API 绘图 组合图作者:方倍工作室 地址: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN& ...
- bfs CCF2016第七次 游戏
// bfs CCF2016第七次 游戏 // 思路: // O(300*100*100) // 直接暴搜 // 注意,同一格同一时间不能经过两次!!! #include <bits/stdc+ ...
- 安装CPqD/ofdissector遭遇的错误
为了安装支持openflow1.3的wireshark插件,在下载了ofdissector.git,并进入了其src目录后,执行scons install,出现如下错误: util/FieldMana ...
- 智能会议白板系统CodeMap
4个人3个月,1个项目,47个工程->白板系统 白板部分: 识别部分: 望多指教.
- anaconda在linux下的安装注意事项
不应该做什么 官网原文: Installation Instructions Linux Install These instructions explain how to install Anaco ...