Sherlock and The Beast

Problem Statement

Sherlock Holmes is getting paranoid about Professor Moriarty, his arch-enemy. All his efforts to subdue Moriarty have been in vain. These days Sherlock is working on a problem with Dr. Watson. Watson mentioned that the CIA has been facing weird problems with their supercomputer, ‘The Beast‘, recently.

This afternoon, Sherlock received a note from Moriarty, saying that he has infected ‘The Beast‘ with a virus. Moreover, the note had the number N printed on it. After doing some calculations, Sherlock figured out that the key to remove the virus is the largest Decent Number having N digits.

Decent Number has the following properties:

  1. 35, or both as its digits. No other digit is allowed.
  2. Number of times 3 appears is divisible by 5.
  3. Number of times 5 appears is divisible by 3.

Meanwhile, the counter to the destruction of ‘The Beast‘ is running very fast. Can you save ‘The Beast‘, and find the key before Sherlock?

Input Format
The 1st line will contain an integer T, the number of test cases. This is followed by T lines, each containing an integer N. i.e. the number of digits in the number.

Output Format
Largest Decent Number having N digits. If no such number exists, tell Sherlock that he is wrong and print −1.

Constraints
1≤T≤20
1≤N≤100000

Sample Input

4
1
3
5
11

Sample Output

-1
555
33333
55555533333

Explanation
For N=1, there is no such number.
For N=3, 555 is the only possible number.
For N=5, 33333 is the only possible number.
For N=11, 55555533333 and all permutations of these digits are valid numbers; among them, the given number is the largest one.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <typeinfo>
using namespace std;

int main() {
    int loops = 0;
    cin>>loops;
    for(int i=0; i<loops; i++){
        int length = 0;
        cin>>length;
        if(length%3==0) {
            string dig(length,‘5‘);
            cout<<dig<<endl;
        }
        else if(length%3==1)
            if(length<10) cout<<-1<<endl;
            else {
                string five(length-10, ‘5‘);
                string three(10,‘3‘);
                cout<<five+three<<endl;
            }
        else
            if(length<5) cout<<-1<<endl;
            else {
                string five(length-5, ‘5‘);
                string three(5,‘3‘);
                cout<<five+three<<endl;
            }
    }
    return 0;
}
时间: 2025-02-01 09:12:39

Sherlock and The Beast的相关文章

【HackerRank】 Sherlock and The Beast

Sherlock and The Beast Sherlock Holmes is getting paranoid about Professor Moriarty, his archenemy. All his efforts to subdue Moriarty have been in vain. These days Sherlock is working on a problem with Dr. Watson. Watson mentioned that the CIA has b

HackerRank - Sherlock and The Beast

Greedy beats DP this time... I tried several DP solutions first, but all failed with RE\TLE. If you 'feel' the problem, Greedy should be working: (A solution from discussion) def getPivot(n): while n > 0: if n % 3 == 0: break; else: n -= 5 return n T

SuperVision - Sherlock 通用界面程序

SuperVision Sherlock 人机界面快速开发(配置)平台 不是软件工程师也能整出专业的 HMI.

Dalsa Sherlock 直连千兆网相机(通用驱动)

支持 Sherlock 7.1.7.2,用于千兆网相机与 Sherlock 的连接. 可适用于很多厂商的相机,如:巴斯勒(Basler),JAI,堡盟相机(Baumer),灰点相机(Point Grey)...等等 1. 支持多个相机连接: 2. 支持黑白和彩色相机的单独或并存连接: 3. 支持采集图像buffer(防漏检),可设置队列的大小,是否启用: 4. 可根据相机序号(sn)进行排序(0,1,2-): 5. 可配置硬件触发.连续触发和初始化时相机的各个参数: 6. 可在sherlock中

Sherlock 连接相机

UsrAcqDriver 说明书 V20140510 UsrAcqDriver.dll 用于千兆网相机与 Sherlock 的连接. 可适用于很多厂商的相机(dalsa就不说了),如:basler,jai,baumer等待… 特点: 1. 最多支持N个相机连接,默认支持最多8个相机的连接: 2. 支持黑白和彩色相机的单独或并存连接: 3. 支持采集图像队列,可以设置队列的大小: 4. 可根据相机序号(sn)对相机的序号进行排序(0,1,2…): 5. 可配置硬件触发.连续触发和初始化时相机的各个

【HackerRank】Sherlock and MiniMax

题目连接:Sherlock and MiniMax Watson gives Sherlock an array A1,A2...AN. He asks him to find an integer M between P and Q(both inclusive), such that, min {|Ai-M|, 1 ≤ i ≤ N} is maximised. If there are multiple solutions, print the smallest one. Input For

【HackerRank】Sherlock and Array

Watson gives an array A1,A2...AN to Sherlock. Then he asks him to find if there exists an element in the array, such that, the sum of elements on its left is equal to the sum of elements on its right. If there are no elements to left/right, then sum

[译]BEAST还是一个威胁吗?

原文链接:https://community.qualys.com/blogs/securitylabs/2013/09/10/is-beast-still-a-threat 原文发表时间:2013.9.10 本博文仅仅是上述原文的翻译,仅供研究参考,本人不对准确性作任何保证,侵立删,如有转载,需自行承担所有责任.如有翻译不准确的地方,欢迎指教. 昨天,我改变了 SSL Labs 的打分规则(译者注:SSL Labs是一个在线检测SSL站点安全性的网站),停止检测站点是否启用了服务端的BEAST

CF776B Sherlock and his girlfriend

CF776B Sherlock and his girlfriend 一个数和它的质因数不能同色. 素数的约数只有本身和1. 显然所有素数都可以染同色,合数同理. 欧拉筛一筛. 注意特判n<3的情况. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define re register 5 using namespace std; 6 #define N 100002 7 int n,v