首页 > 其他 > 详细

HackerRank - Sherlock and The Beast

时间:2015-03-02 12:44:29      阅读:287      评论:0      收藏:0      [点我收藏+]

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 = input()
for i in xrange(T):
    N = int(input())
    pivot = getPivot(N)
    if pivot < 0:
        print -1
    else:
        str = ‘‘
        repeat = pivot / 3
        while repeat > 0:
            str += 555
            repeat -= 1
        repeat = (N - pivot) / 5
        while repeat > 0:
            str += 33333
            repeat -= 1
        print str

HackerRank - Sherlock and The Beast

原文:http://www.cnblogs.com/tonix/p/4308337.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!