Noip recommendation series: Remote control vehicles [String + high precision + second answer]

Source: Internet
Author: User

[Problem description]

Pingping came to the amusement park with Yun and saw n beautiful remote control vehicles. Each car had a unique name [I]. Yun can't wait to play the remote control car named S. However, Yun is still small. The name she imagined may be the prefix of a car name (that is, the prefix of name [I] can be determined ), in this case, she can play the I car, or an out-of-the-box name, that is, S is not the prefix of any car name. At this time, she can't play anything. You need to complete the following tasks:

1. Yun thought about M names she wanted. Please tell her how many times she could play.

2. due to the careless operations of the Administrator, the placement of each vehicle may be slightly incorrect, the current position of the I car may be any of the I-1, I, I + 1 (the location of the 1st car cannot be 0, the location of the N-car cannot be n + 1 ). Please calculate the total number of possible arrangements.

Note: Data guarantee that when S is the prefix of name [I], I is uniquely identified. A car can be played multiple times.

[Input file]

The first line is two positive integers n and M.

In the next n rows, each line has a string name [I], which indicates the name of the I-th car.

In the next M line, each line has one string, S, indicating the desired name of the rhyme.

[Output file]

The first row outputs the number of times the rhyme can be played.

How many possible arrays are output in the second row.

[Input example]

4

ABCD

Def

Aaa

Abccc

AB

AA

ABC

ABCC

[Output example]

3

5

[Data scale and Conventions]

The strings involved in the question are case sensitive and the length is less than 255.

For 20% of data, n ≤ 10, m ≤ 10;

For 40% of data, n ≤ 1000, m ≤ 1000;

For 100% of data, n ≤ 10000, m ≤ 10000.

 

I feel that there are a lot of great questions in the recommendation series, which is also good and requires a lot of skills.

The score for this question is better.

Find the number of all the cars that can be seated correctly + write the recurrence formula correctly-> 40 (wa3 timed out 3)

Recurrence + high-precision processing-> 70 (timeout 3)

Sorting + binary answer-> 100

 

If it is high-precision, I will exercise a few questions before the test, so I am too lazy to say it here.

Let's talk about the expected score of 100.

Sorting + binary answers are rarely used in strings. I have learned a bit.

 

We should first sort the names of all vehicles (SORT)

Because the question says, "data ensures that when S is the prefix of name [I], I is uniquely identified"

This statement is very important, which means that s cannot be the prefix of more than one name.

The information we provided is that this question uses a binary answer, rather than a binary answer, to get the upper and lower bounds (so pay attention to the words used in the question)

 

The code is simple:

 

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;const int maxn=10001;string s[maxn],c[maxn];int a[1001],b[1001],d[1001];int n,m,l;long long ans=0;void jia(){memset(d,0,sizeof(d));int m=0;for(int i=1;i<=l+1;i++){d[i] += a[i] + b[i] + m;m = d[i]/10;d[i] %= 10;}if(d[l+1]) l++;for(int i=1;i<=l;i++) a[i] = b[i];for(int i=1;i<=l;i++) b[i] = d[i];}int main(){       freopen("car.in","r",stdin);       freopen("car.out","w",stdout);       //freopen("data.txt","r",stdin);       scanf("%d%d",&n,&m);       a[1]=1;b[1]=2;       l=1;       for(int i=1;i<=n;i++){    cin>>s[i];    if(i>=3) jia();       }       sort(s+1,s+n+1);       for(int i=1;i<=m;i++){             cin>>c[i];            int l=1,r=n,mid;            while(l<r){        mid=(l+r)>>1;        if(c[i]<=s[mid]) r=mid;        else l=mid+1;        }        if(s[l].find(c[i],0)==0) ans++;}cout<<ans<<"\n";for(int i=l;i>=1;i--) cout<<d[i];return 0;}

 

  

 

Noip recommendation series: Remote control vehicles [String + high precision + second answer]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.