博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[F] Teacher's Problem(处理大数时,优化很重要)
阅读量:4037 次
发布时间:2019-05-24

本文共 1561 字,大约阅读时间需要 5 分钟。

1、

2、题目大意:

有n个字符串,每个字符串都有一个价值,如果第i个字符串是第j个字符串的前缀,那么第i个字符串就是第j个字符串的父亲,这样就会组成一棵树,子节点的价值都更新到父节点的价值上,然后按顺序输出即可

3、题目:

  • [F] Teacher's Problem

  • 时间限制: 2000 ms 内存限制: 262144 K       

  • 问题描述
  • One day my teacher gave me a problem to solve. I was given N unique names andeach name has a value. Name is a string consisting of lowercase Latin letters withlength less than 10. Value is a positive integer less than 100. Initially these namesare sorted in lexicographic order. Now if the j-th name is the prefix of the i-th nameand has the max length, j is thefather of i. Then numbers 1 to N form a tree. Fromleafto root, each son's value should be added to father's value. After I added thesevalues, my teacher ask me to show allthese values.

    Can you help me with the problem?

  • 输入
  • First line there is an integer T (T < 20) following T test cases.
    For each test case, first line is an integer N (0 < N <= 10^5), second line is N names, third line is N values.
    Names and values are separate by a space. There is no space at the end of line.
    Names are all unique and are given in Lexicographic order.           
  • 输出
  • For each test case, please output one line with N integers. The i-th integer is the i-th value after added.
    Please do not output a space at the end of line.           
  • 样例输入
  • 23a ab ac5 10 155a ab abb ac b5 10 100 15 6
  • 样例输出
  • 30 10 15130 110 100 15 6
  • 提示
  • Huge input, scanf is recommended.
  • 来源
  • zzxchavo @HEU

    4、Ac代码:

    #include
    #include
    #include
    using namespace std;#define N 100005char s[N][12];int w[N];int check(int a,int b){ int len=strlen(s[a]); for(int i=0;i

     

转载地址:http://igddi.baihongyu.com/

你可能感兴趣的文章
【剑指offer】面试题26:复杂链表的复制
查看>>
【leetcode】Candy(python)
查看>>
【leetcode】Clone Graph(python)
查看>>
【leetcode】Sum Root to leaf Numbers
查看>>
【leetcode】Pascal's Triangle II (python)
查看>>
java swing最简单实例(2) 往JFrame里面放一个容器或组件
查看>>
java自定义容器排序的两种方法
查看>>
如何成为编程高手
查看>>
本科生的编程水平到底有多高
查看>>
AngularJS2中最基本的文件说明
查看>>
从头开始学习jsp(2)——jsp的基本语法
查看>>
从头开始学习JSP(3)——一些配置
查看>>
html常用标签快速检索
查看>>
使用与或运算完成两个整数的相加
查看>>
备忘:java中的递归
查看>>
DIV/CSS:一个贴在左上角的标签
查看>>
通过/proc/PID/status查看进程内存占用情况
查看>>
/proc文件系统读出来的数据是最新的吗?
查看>>
Solr及Spring-Data-Solr入门学习
查看>>
Vue组件
查看>>