Type the Question

Thursday, February 21, 2019

Question Name: SHERLOCK AND THE BEAST

#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility> 
using namespace std;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
 
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define Pi 3.14159265358979

typedef long long Int;
typedef unsigned long long UInt;
typedef vector <int> VI;
typedef pair <int, int> PII;



int main()
{
  
 int T;
 cin>>T;
 REP(tests,T)
 {
  int n;
  cin>>n;
  
  int res = -1;
  
  for (int i = 0; i <= n; ++i)
  {
   if (i % 5 == 0)
   {
    int j = n - i;
    
    if (j % 3 == 0)
    {
     res = i;
     break;
    }
   }
  }
  
  if (res == -1)
  {
   cout << -1 << endl;
   continue;
  }
  
  REP(i,n-res)
   putchar('5');
  REP(i,res)
   putchar('3');
  puts("");
 }

 
 return 0;
}
  • Problem Description
    Sherlock Holmes suspects his archenemy, Professor Moriarty, is once again plotting something diabolical. Sherlock’s companion, Dr. Watson, suggests Moriarty may be responsible for MI6’s recent issues with their supercomputer, The Beast.

    Shortly after resolving to investigate, Sherlock receives a note from Moriarty boasting about infecting The Beast with a virus; however, he also gives him a clue a number, N. Sherlock determines the key to removing the virus is to find the largest Decent Number having N digits.

    A Decent Number has the following properties:

    1. Its digits can only be 3’s and/or 5’s.
    2. The number of 3’s it contains is divisible by 5.
    3. The number of 5’s it contains is divisible by 3.
    4. If there are more than one such number, we pick the largest one.
    Constraints:
    1 <= T <= 20
    1 <=N <= 100000

    Input Format:

    The first line is an integer, T , denoting the number of test cases.

    The T subsequent lines each contain an integer, N, detailing the number of digits in the number.

    Output Format

    Print the largest Decent Number having N digits; if no such number exists, tell Sherlock by printing -1.

    Moriarty’s virus shows a clock counting down to The Beast’s destruction, and time is running out fast. Your task is to help Sherlock find the key before The Beast is destroyed!
  • Test Case 1
    Input (stdin)4
    1
    3
    5
    11
    Expected Output-1
    555
    33333
    55555533333
  • Test Case 2
    Input (stdin)3
    5
    7
    11
    Expected Output33333
    -1
    55555533333

No comments:

Post a Comment

Question Name:TOWER OF HANOI

#include < bits / stdc ++. h > #define lli long long using namespace std ; lli dp [ 202 ]; int main () { int t , n ; ...