Sherlock and The Beast
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, . Sherlock determines the key to removing the virus is to find the largest Decent Number having digits.
A Decent Number has the following properties:
- Its digits can only be 3's and/or 5's.
- The number of 3's it contains is divisible by 5.
- The number of 5's it contains is divisible by 3.
- If there are more than one such number, we pick the largest one.
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!
Constraints
1 =< T <= 20
1 <= N <= 100000
Input Format
The first line is an integer, , denoting the number of test cases.
The subsequent lines each contain an integer, , detailing the number of digits in the number.
Output Format
Print the largest Decent Number having digits; if no such number exists, tell Sherlock by printing -1.
Sample Input
4
1
3
5
11
Sample Output
-1
555
33333
55555533333
题目大意:组成的数:5的个数能被3整除,3的个数能被5整除,找最大的那个数,显然满足条件的数中所有的5在位的前面是最大的数。5和3的个数等于n,找满足条件的5的个数最多的那个数,
一开始设5的个数为n,判断是否满足条件,否则5的个数为n-1,一直遍历,找到满足的一组则立即结束遍历,若遍历到5的个数为0,也没有找到满足条件的一组数,则输出“-1”
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std; int main(){
int t;
cin >> t;
for(int a0 = ; a0 < t; a0++){
int n;
cin >> n;
int digit_five, digit_three, flag = ;
for(int i = n; i >= ; i--){
if(i % == && (n-i) % == ){
digit_five = i;
digit_three = n - i;
flag = ;
break;
}
}
if(flag == ){
cout << "-1" << endl;
continue;
}
for(int i = ; i < digit_five; i++)
cout << '';
for(int i = ; i < digit_three; i++)
cout << '';
cout << endl;
}
return ;
}
Sherlock and The Beast的更多相关文章
- 【HackerRank】 Sherlock and The Beast
Sherlock and The Beast Sherlock Holmes is getting paranoid about Professor Moriarty, his archenemy. ...
- 16061701(地图灯光编译Beast报错)
[目标] 地图灯光编译报错 [思路] 1 我自己测c2_cwd_rt 附件为当时log 2 ExampleGame\BeastCache\PersistentCache 3 重新删除掉BeastCac ...
- [译]BEAST还是一个威胁吗?
原文链接:https://community.qualys.com/blogs/securitylabs/2013/09/10/is-beast-still-a-threat 原文发表时间:2013. ...
- Chapter 1 Mr.Sherlock Holmes
I took my degree of Doctor of Medicine in the University of London, and proceeded to Netley to go th ...
- Dalsa Sherlock 直连千兆网相机(通用驱动)
支持 Sherlock 7.1.7.2,用于千兆网相机与 Sherlock 的连接. 可适用于很多厂商的相机,如:巴斯勒(Basler),JAI,堡盟相机(Baumer),灰点相机(Point Gre ...
- Gym - 101350A Sherlock Bones(思维)
The great dog detective Sherlock Bones is on the verge of a new discovery. But for this problem, he ...
- Monster: half man, half beast and very scary.
Monster: half man, half beast and very scary. 怪物,半人半兽很吓人.
- [译]缓解BEAST对TLS攻击的方式
原文链接:https://community.qualys.com/blogs/securitylabs/2011/10/17/mitigating-the-beast-attack-on-tls 原 ...
- [译]SSL/TLS真的被BEAST攻击攻破了吗?真实情况是怎样的?我应该做什么?
原文链接:https://luxsci.com/blog/is-ssltls-really-broken-by-the-beast-attack-what-is-the-real-story-what ...
随机推荐
- POJ 1611 The Suspects (并查集)
The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( S ...
- c语言函数的可选性自变量
功能: 宏va_arg()用于给函数传递可变长度的参数列表. 首先,必须调用va_start() 传递有效的参数列表va_list和函数强制的第一个参数.第一个参数代表将要传递的参数的个数. 其次,调 ...
- Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...
- POJ 3670 Eating Together (DP,LIS)
题意:给定 n 个数,让你修改最少的数,使得它变成一个不下降或者不上升序列. 析:这个就是一个LIS,但是当时并没有看出来...只要求出最长LIS的长度,用总数减去就是答案. 代码如下: #inclu ...
- hdu 4786 Fibonacci Tree (2013ACMICPC 成都站 F)
http://acm.hdu.edu.cn/showproblem.php?pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) ...
- 用6个字符写出任意的Javascript代码
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:用6个字符写出任意的Javascript代码.
- 行内onclick使用遇坑--------作用域与传入字符串
问题一:行内onclick触发的函数放在$(funtion(){})内报错,错误代码如下: <input type="button" value="确定" ...
- 【转】shell脚本处理字符串的常用方法
转自:http://blog.csdn.net/linfeng999/article/details/6661233 1. 构造字符串 直接构造 STR_ZERO=hello #shell中等号左右的 ...
- android 手电筒的实现
android手机用闪光灯做成手电筒的应用非常多,可是有的不能用. 后来发现是除了把 camera device的 flashmode设置成torch外还要打开预览: 以下是代码: MainActiv ...
- 【M8】了解各种不同意义的new和delete
1.首先考虑new operator,new operator 可以认为做了三件事情:a.调用operator new分配一块内存:b.在这块内存上调用构造方法构造对象:返回指针. 2.operato ...