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 暴力的更多相关文章

  1. TC SRM 665 DIV2 B LuckyCycle 暴力

    LuckyCycleTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.ac ...

  2. TC SRM 663 div2 A ChessFloor 暴力

    ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a squa ...

  3. TC SRM 664 div2 A BearCheats 暴力

     BearCheats Problem Statement    Limak is an old brown bear. Because of his bad eyesight he sometime ...

  4. TC SRM 663 div2 B AABB 逆推

    AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many En ...

  5. TC SRM 607 DIV2

    求拼接完成后的字符串包含的子回文串的数目,一开始还用暴力去做,想都不用想 肯定超时了. 复习了一下求最长子回文串的算法,发现可以类似解决. 给相邻字符之间添加一个'@'字符,这样所有的回文串都是奇数长 ...

  6. TC SRM 593 DIV2 1000

    很棒的DP,不过没想出,看题解了..思维很重要. #include <iostream> #include <cstdio> #include <cstring> ...

  7. TC SRM 591 DIV2 1000

    很不错的一题,非常巧妙的用DP顺序解决这个问题... 可以发现,只和A里面最小的有关系... #include <cstdio> #include <cstring> #inc ...

  8. tc srm 636 div2 500

    100的数据直接暴力就行,想多了... ac的代码: #include <iostream> #include <cstdio> #include <cstring> ...

  9. TC SRM 664 div2 B BearPlaysDiv2 bfs

    BearPlaysDiv2 Problem Statement    Limak is a little bear who loves to play. Today he is playing by ...

随机推荐

  1. JavaScript--事件模型(转)

    在各种浏览器中存在三种事件模型:原始事件模型( original event model),DOM2事件模型,IE事件模型.其中原始的事件模型被所有浏览器所支持,而DOM2中所定义的事件模型目前被除了 ...

  2. mbr grub的区别

    mbr是磁盘的物理扇区,不是程序名: 因为BIOS很小,功能有限,为了完成加载操作系统的功能,就产生了mbr: bios检测到一个硬盘后,将硬盘的0柱面.0磁头.1扇区的内容经过简单判断后, 至内存中 ...

  3. python学习资源

    12岁的少年教你用Python做小游戏: http://blog.jobbole.com/46308/ python视频教程大全集: http://www.douban.com/group/topic ...

  4. STM32F407 外扩SRAM

    字节控制功能.支持高/低字节控制. 看看实现 IS62WV51216 的访问,需要对 FSMC进行哪些配置. 这里就做一个概括性的讲解.步骤如下: 1)使能 FSMC 时钟,并配置 FSMC 相关的  ...

  5. 常用SQL语句汇总整理

    1.SQL 插入语句得到自动生成的递增ID 值 insert into Table1(Name,des,num) values (''ltp'',''thisisbest'',10); select ...

  6. ORA-15124 数据库启动阶段报错

    重新进行启动数据库的时候报错: SQL> startup nomount; ORA-15124: ASM file name '+KEL/ipap/controlfile/control02.c ...

  7. C++ 我想这样用(六)

    嗯,上一篇已经介绍了面向过程编程的语法知识,接下来是最后的也是最重要的一个部分: 第三部分:基于对象的编程风格 1.构造函数的两种写法 比如我们有如下的类定义: class Circle { publ ...

  8. C# 与 VC Dll 传输信息

    考虑: 使用string类型传送: 在VC Dll中解析字符: 使用 string 类型将解析的类型传送到C#程序中: 建立VC解析的函数,提高代码可重用性

  9. HDU5744:Keep On Movin(字符串)

    题意: 给出t组测试数据,每组给出正整数n表示有n种字符,接下来给出n个数表示该种字符的数目,操作一下,使得可以构造的最小回文串字符数目最大且输出. 分析: 如果每个字符出现次数都是偶数, 那么答案显 ...

  10. 自己实现Single LinkedList

    My_Single_LinkedList 分4个部分实现(CRUD - 增删改查). 首先要有一个Node(节点类) class Node { public int val; public Node ...