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%10;
            if(X==4||X==7)
                x/=10;
            else
                return 0;

        }
        return 1;
    }
    int construct(int a){
        int ans=-1;
        for(int i=a+1;i<=100;i++)
        {
            int X=(a^i);
            if(check(X)==1)
            {
                ans=i;
                break;
            }
        }
        return ans;
    }
};
时间: 2024-08-25 01:04:31

TC SRM 665 DIV2 A LuckyXor 暴力的相关文章

TC SRM 663 div2 A ChessFloor 暴力

ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a square room. The floor of the room is an N times N grid of unit square tiles. Each tile has some color. You are given the current colors of all tiles in a

TC SRM 663 div2 B AABB 逆推

AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many English words only use the letters A and B. Examples of such words include "AB" (short for abdominal), "BAA" (the noise a sheep makes), &

TC SRM 664 div2 AB

#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; class BearCheats{ public: string eyesight(int A, int B){ char t[256]; string s1; sprintf(t, "%d", A); s1 = t; string s2; cha

TC SRM 664 div2 B BearPlaysDiv2 bfs

BearPlaysDiv2 Problem Statement    Limak is a little bear who loves to play. Today he is playing by moving some stones between three piles of stones. Initially, the piles contain A, B, and C stones, respectively. Limak's goal is to produce three equa

tc srm 636 div2 500

100的数据直接暴力就行,想多了... ac的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <algorithm> 7 #include <vector> 8 #define LL __int64 9 const int maxn =

TC SRM 636 Div2 C ChocolateDividingHard 二分

先把行合并,然后二分一下最小值就好. // BEGIN CUT HERE // END CUT HERE #line 5 "ChocolateDividingHard.cpp" #include <cstdlib> #include <cctype> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> #include

TC SRM 670 div2 Treestart

题目大意: 一个树状的棋盘,A,B两种棋子.初始时没有棋子重合,每一轮AB轮流移动任意个(包括不移动)自己的棋子,可以重合.如果某一时刻一格子上同时存在A和B两种棋子,则B获胜.A尽量使游戏进行的总轮数最多,B尽量在最少的轮数获胜(B 一定能获胜),输出最少轮数. 解题思路: 单独考虑A的每个棋子,每次分别扩展并跟新A和B能到的格子,如果A能到的格子中没有B不能到的,那么B胜利. 由于只有50个点,可以用状态压缩来让代码变得更加优美一点~! using namespace std; vector

SRM 630 DIV2

SRM 630 DIV2 第一次TC,本来以为AK了,结果1000分还是被系统cha掉了,不过倒是也cha掉了房间其他人赚了不少 A:字符串长度才50,直接简单的模拟即可 B:结点个数才10,先做一边floyd,找出两两之间路径,然后暴力枚举选哪些点,判断可不可以,如果可以的话,记录下最大个数 C:一开始的做法是,构造出rank数组后,对于连续的一段,都放a,然后最后一个放b即可,以为这样构造出来的肯定是字典序最小的,结果被系统cha掉了. 正确做法:一开始先构造出sa数组,暴力枚举每个位置,非

SRM 628 DIV2

250  想想就发现规律了. 500  暴力,括号匹配. 1000 给一个f数组,如果i存在,那么f[i]也得存在,问这样的集合有多少种. 先拓扑一下,dp[i] = mul(dp[son]+1)最后环里面的元素的乘积是结果. #include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <stdlib.h> #include <v