07: Machine Translation, 07: Machine Translation

Source: Internet
Author: User

07: Machine Translation, 07: Machine Translation
7: Machine Translation

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

John installed a machine translation software on his computer. He often used it to translate English articles.

The principle of this translation software is very simple. It only replaces each English word with the corresponding Chinese meaning from start to end. For each English word, the software first searches for the Chinese meaning of the word in the memory. If there is memory, the software will use it for translation; if there is no memory, the software searches in the external dictionary, finds out the Chinese meaning of the word, translates it, and puts the word and translation into the memory for subsequent search and translation.

Assume that there are M units in the memory, and each unit can store a word and a translation. Every time the Software saves a new word to the memory, if the number of words in the current memory does not exceed M-1, the software will store the new word into an unused memory unit; if M words have been stored in the memory, the software clears the words that first enter the memory, freeing up units to store new words.

Assume that an English article contains N words. Given this article to be translated, How many times does the translation software need to store the dictionary? Assume that there are no words in the memory before the translation starts.

Input
The input file contains two rows. Separate two numbers in each row with a space.
The first two positive integers M and N represent the memory capacity and the length of the article.
The second act contains N non-negative integers. In the order of the document, each number (up to 1000 in size) represents an English word. In this article, two words are the same word, if and only if their corresponding non-negative integers are the same.

For 10% of data, M = 1, N ≤ 5.
For 100% of data, 0 <M ≤ 1000, 0 <N ≤.
Output
A total of one row, containing an integer, is the number of times the software needs to query the dictionary.
Sample Input
Example #71 2 1 5 4 4 1 example #108 11 78 11 78 11 78 8 824
Sample output
Example # example #
Prompt
Input and Output Example 1:

The entire dictionary search process is as follows: each line indicates the translation of a word, and the memory condition after this translation is before the colon:

Null: the initial memory status is empty.
1. 1: Search for word 1 and transfer it to the memory.
2. 1 2: Search for word 2 and transfer it to the memory.
3. 1 2: Find word 1 in memory.
4. 1 2 5: Find the word 5 and transfer it to the memory.
5 4: Search for word 4 and call the memory to replace word 1.
6. 2 5 4: Find the word 4 in the memory.
4 1: Search for word 1 and call the memory to replace word 2.

A total of five dictionaries were queried.
1 # include <iostream> 2 # include <cstring> 3 # include <cstdio> 4 # include <cmath> 5 # include <queue> 6 # include <vector> 7 # include <algorithm> 8 using namespace std; 9 int m; // memory capacity: 10 int n; // Article length: 11 int a [1001]; // store the current dictionary 12 vector <int> zd; // store the dictionary 13 int tot in the memory; // The number of times to be searched 14 int find (int tot) 15 {16 for (int I = 1; I <= n; I ++) // 1 2 1 5 4 4 117 {18 if (find (zd. begin (), zd. end (), a [I]) = zd. end () 19 {20 if (zd. size () = m) 21 {22 zd. erase (zd. begin (); // Delete the first element 23 zd. push_back (a [I]); 24 tot ++; 25} // memory full 26 else27 {28 zd. push_back (a [I]); 29 tot ++; 30} 31} // No element 32 else33 continue found; // 34 35} is returned directly after finding it. // traverse each character 36 return tot; 37} 38 int main () 39 {40 cin> m> n; 41 for (int I = 1; I <= n; I ++) 42 cin> a [I]; 43 cout <find (0); 44 return 0; 45}

 

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.