Codejam 2009 qualification round question C

关键还是要把问题想通透,然后就很简单了。

 

'''
CodeJam Practice 2009 qualification round question C
Created on 2012-12-18

@author: festony
'''

from cj_lib import *
from properties import *

curr_file_name = 'C-large-practice'
#curr_file_name = 'C-small-practice'
#curr_file_name = 'test'


def input_dividing_func(input_lines):
    total_case = int(input_lines.pop(0))
    case_inputs = input_lines[:total_case]
    return case_inputs

target = 'welcome to code jam'

def count_time_char(c, time_counts_char):
    for i, t in enumerate(target):
        if t == c:
            time_counts_char[i] += time_counts_char[i+1]
            time_counts_char[i] = time_counts_char[i] % 10000
            
# time_counts: holds how many times has a certain char sequence appeared in previous str.
# each element of time_counts is also a list:
# 0: time counts for 'welcome to code jam'
# 1: time counts for 'elcome to code jam'
# 2: time counts for 'lcome to code jam'
# 3: time counts for 'come to code jam'
# 4: time counts for 'ome to code jam'
# 5: time counts for 'me to code jam'
# 6: time counts for 'e to code jam'
# 7: time counts for ' to code jam'
# 8: time counts for 'to code jam'
# 9: time counts for 'o code jam'
# 10: time counts for ' code jam'
# 11: time counts for 'code jam'
# 12: time counts for 'ode jam'
# 13: time counts for 'de jam'
# 14: time counts for 'e jam'
# 15: time counts for ' jam'
# 16: time counts for 'jam'
# 17: time counts for 'am'
# 18: time counts for 'm'
# 19: 1 to simplify calculation.
#
# theory: Check input string from end to beginning. At any point, say, for example if
# 'w' appears one time, and after this 'w', seq 'elcome to code jam' has appearred 5 times,
# then full term 'welcome to code jam' till now have 5 different position combination (
# time_counts_char[0] was 0, time_counts_char[1] was 5, now time_counts_char[0] += 
# time_counts_char[1], then time_counts_char[0] becomes 5). Then keep going forward to the
# beginning of the input string, suddenly 'w' appears again, then combine with previous one
# 'w' and 5 different 'elcome to code jam', full term now may appear 10 times(
# time_counts_char[0] was 5, time_counts_char[1] was 5, now time_counts_char[0] +=
# time_counts_char[1], then time_counts_char[0] becomes 10). etc etc.
    
def process_func(func_input):
    in_seq = list(func_input)
    in_seq.reverse()
    time_counts = [[0]*len(target) + [1]]*len(in_seq)
    for i, time_counts_char in enumerate(time_counts):
        count_time_char(in_seq[i], time_counts_char)
    return '%04d' % time_counts[len(in_seq) - 1][0]

run_proc(process_func, input_dividing_func, curr_working_folder, curr_file_name)



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值