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 ...
随机推荐
- Ruby窗口程序
require 'tk' tkroot=TkRoot.new { title 'hellw word' geometry '300x200' } lb = TkLabel.new(tkroot) do ...
- Mysql 的存储过程和存储函数
优点: v 提高安全性 v 简化mysql查询 v 减轻带宽负担 缺点: v 增加服务器负担 v 对我们开发者来说,难度大一点 PHP中的函数 Function funname(参数){ //函数体 ...
- [转]LINK:fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
LINK:fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 原文地址:http://yacare.iteye.com/blog/2010049 很多伙伴在更新VS ...
- Procdure for wanfo business report
CREATE OR REPLACE PROCEDURE PROC_TZ_EXEC_N_YEARREPORT(ssrq varchar2 ) as -----声明变量 v_raise EXCEPTION ...
- IOS release 版本的时候 去掉输出log NSLog
在.pch文件中添加下面一段 #ifndef __OPTIMIZE__ #define NSLog(...) NSLog(__VA_ARGS__) #else #define NSLog(...) { ...
- Linux基本命令(1)管理文件和目录的命令
Linux管理文件和目录的命令 命令 功能 命令 功能 pwd 显示当前目录 ls 查看目录下的内容 cd 改变所在目录 cat 显示文件的内容 grep 在文件中查找某字符 cp 复制文件 touc ...
- Multiple View Geometry in Computer Vision Second Edition by Richard Hartley 读书笔记(二)
// Chapter 2介绍的是2d下的投影变换,摘录下了以下定理 Result 2.1. The point x lies on the line l if and only if xTl = 0. ...
- unicode ansi utf-8 unicode_big_endian编码的区别
随便说说字符集和编码 快下班时,爱问问题的小朋友Nico又问了一个问题: "sqlserver里面有char和nchar,那个n据说是指unicode的数据,这个是什么意思.&quo ...
- C/C++:类模板
类模板就是为类声明一种模板,使得类中的某些数据成员,或某些成员函数的参数,又或者是某些成员函数的返回值可以取任意的数据类型,包括基本数据类型和自定义数据类型. 类模板的声明形式如下: template ...
- 初学AngularJS
最近一直想写个网站,所以在做技术准备.在搜索资料的过程中发现了AngularJS,于是顺藤摸瓜找到了一些资料. 学习的最好途径是:上课. 其次是:看录像: ...