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. win下Java环境安装

    1.eclipse:eclipse.org  解压后直接打开 2.JDK:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-do ...

  2. [FIX BUG]获取theme中自定义textColor时报的错误

    我在Fragment中inflate它都可以,可是一旦使用ListView来inflate就会报错,说找不到我自定义的attr!研究了半天发现是我的inflate的context有问题: view = ...

  3. POJ 1064 Cable master

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37865   Accepted: 8051 Des ...

  4. [Papers]NSE, $u_3$, Lebesgue space [Jia-Zhou, NARWA, 2014]

    $$\bex u_3\in L^\infty(0,T;L^\frac{10}{3}(\bbR^3)). \eex$$

  5. C++ STL算法系列1---count函数

    一.count函数 algorithm头文件定义了一个count的函数,其功能类似于find.这个函数使用一对迭代器和一个值做参数,返回这个值出现次数的统计结果. 编写程序读取一系列int型数据,并将 ...

  6. ORACLE临时表总结[转]

    临时表概念 临时表就是用来暂时保存临时数据(亦或叫中间数据)的一个数据库对象,它和普通表有些类似,然而又有很大区别.它只能存储在临时表空间,而非用户的表空间.ORACLE临时表是会话或事务级别的,只对 ...

  7. 【Opencv 小工具】鼠标选区信息获取

    有时候在目标跟踪的算法初始化工作时候,需要选区一个Rect区域,来表示要跟着的目标,所以有次小工具. 使用QT和opencv 编写 项目地址 https://github.com/wzyuliyang ...

  8. Python对象体系揭秘

    Guido用C语言创造了Python,在Python的世界中一切皆为对象. 一.C视角中的Python对象 让我们一起追溯到源头,Python由C语言实现,且向外提供了C的API http://doc ...

  9. 二分+叉积判断方向 poj 2318 2398

    // 题意:问你每个区域有多少个点 // 思路:数据小可以直接暴力 // 也可以二分区间 #include <cstdio> #include <cstring> #inclu ...

  10. ubuntu使用问题与解决记录[持续更新]

    1. 添加到计划任务 为脚本增加可执行权限 sudo chmod +x yeelink.sh 将脚本加入cronjob(计划任务) sudo crontab -e 在cornjob文件中添加下面一行, ...