zoukankan      html  css  js  c++  java
  • ACM HDU 3460 Ancient Printer(简单题)

    Ancient Printer

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
    Total Submission(s): 704    Accepted Submission(s): 309


    Problem Description
    The contest is beginning! While preparing the contest, iSea wanted to print the teams' names separately on a single paper.
    Unfortunately, what iSea could find was only an ancient printer: so ancient that you can't believe it, it only had three kinds of operations:

    ● 'a'-'z': twenty-six letters you can type
    ● 'Del': delete the last letter if it exists
    ● 'Print': print the word you have typed in the printer

    The printer was empty in the beginning, iSea must use the three operations to print all the teams' name, not necessarily in the order in the input. Each time, he can type letters at the end of printer, or delete the last letter, or print the current word. After printing, the letters are stilling in the printer, you may delete some letters to print the next one, but you needn't delete the last word's letters.
    iSea wanted to minimize the total number of operations, help him, please.
     

    Input
    There are several test cases in the input.

    Each test case begin with one integer N (1 ≤ N ≤ 10000), indicating the number of team names.
    Then N strings follow, each string only contains lowercases, not empty, and its length is no more than 50.

    The input terminates by end of file marker.
     

    Output
    For each test case, output one integer, indicating minimum number of operations.
     

    Sample Input
    2 freeradiant freeopen
     

    Sample Output
    21
    Hint
    The sample's operation is: f-r-e-e-o-p-e-n-Print-Del-Del-Del-Del-r-a-d-i-a-n-t-Print
     

    Author
    iSea @ WHU
     

    Source
     

    Recommend
    zhouzeyong
     
     
    #include<iostream>
    #include
    <string.h>
    #include
    <algorithm>
    #include
    <stdio.h>
    using namespace std;
    string w[10005];
    int calc(string a,string b)
    {
    int i;
    for(i=0;i<a.length()&&i<b.length()&&a[i]==b[i];i++);
    return a.length()-i+b.length()-i;
    }
    int main()
    {
    int n,i;
    while(scanf("%d",&n)!=EOF)
    {
    for(i=0;i<n;i++) cin>>w[i];
    sort(w,w
    +n);
    int sum=w[0].length()+1;
    int MAX=w[0].length();
    for(i=1;i<n;i++)
    {
    sum
    +=calc(w[i],w[i-1])+1;
    if(w[i].length()>MAX)
    MAX
    =w[i].length();
    }
    printf(
    "%d\n",sum+w[n-1].length()-MAX);
    }
    return 0;
    }

  • 相关阅读:
    基于flash的web视频对讲直播测试
    终于放弃Windows下丑陋的cmd
    直播推流兼容性问题追踪
    32位和64位dll判断
    H264编码参数的一些小细节
    cmake编译win下64位obs
    The certificate used to sign "XXX" has either expired or has been revoked
    记录一次Android交叉编译ffmpeg排查错误
    SDK "iphoneos" cannot be located
    av_interleaved_write_frame 网络不好的情况下返回较慢
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2130824.html
Copyright © 2011-2022 走看看