TopCoder SRM665 Div2 A
来源:互联网 发布:java 角色权限管理 编辑:程序博客网 时间:2024/06/05 00:27
Problem Statement
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.
Definition
Class:
LuckyXor
Method:
construct
Parameters:
int
Returns:
int
Method signature:
int construct(int a)
(be sure your method is public)
Limits
Time limit (s):
2.000
Memory limit (MB):
256
Stack limit (MB):
256
Notes
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
Constraints
a is between 1 and 100, inclusive.
Examples
0)
4
Returns: 40
4 XOR 40 = 44, 44 is a lucky number.
1)
19
Returns: 20
19 XOR 20 = 7
2)
88
Returns: 92
88 XOR 92 = 4
3)
36
Returns: -1
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
题意
只包含4和7的数字是幸运数字,现在给一个数字
题解
代码
class LuckyXor {public: int construct(int);};int LuckyXor::construct(int a) { int s[]={4,7,44,47,74,77}; int t; for(int i=0;i<6;i++) { t=a^s[i]; if(t<=100&&t>=1&&t>a) return a^s[i]; } return -1;}
- TopCoder SRM665 Div2 A
- TopCoder SRM665 Div2 B
- Topcoder SRM 636 Div2 A
- TopCoder SRM 637 Div2 A
- topcoder SRM 513 DIV2
- TopCoder SRM 543 DIV2
- topcoder 544 div2
- Topcoder SRM548 div2
- topcoder-srm-233-div2
- Topcoder SRM Div2 Level2
- topcoder-595-div2
- topcoder srm606 div2
- topcoder srm607 div2
- TopCoder SRM 144 div2
- TOPCODER SRM 612 DIV2
- TOPCODER SRM 613 DIV2
- TopCoder SAM 631 DIV2
- [Topcoder]SRM632 div2 题解
- pip的安装,更新,卸载模块以及使用方法 python
- linux mmap 映射文件
- zeromq-4.1.2在windows下的编译
- 学习JS(5)
- 【UITextField与UITextView】
- TopCoder SRM665 Div2 A
- 清心野人V2.0正式开启
- 1060. Are They Equal (25)
- Sicily 1036 Crypto Columns
- 网易yum源配置 CentOS6.5
- Linux GCC常用命令
- ListView和Adapter
- Android工程师面试宝典&面试实战试题详解01
- 算法思想篇(2)————递推算法