NOIP2009 Improve group T3 machine translation Problem solving report-S.B.S

Source: Internet
Author: User

Topic background

A machine translation software was installed on the morning computer, and he often used the software to translate English articles.

Title Description

The principle of this translation software is very simple, it is just from beginning to end, in turn each English word with the corresponding Chinese meaning to replace. For each English word, the software will first find the Chinese meaning of the word in memory, if there is memory, the software will use it for translation, if not in memory, the software will be found in the dictionary in the external memory, find out the Chinese meaning of the word and translate, and put this word and translation into memory, in case of subsequent search and translation.

Suppose there are m cells in memory, and each unit can hold a word and translate it. Whenever the software stores a new word in memory, if the number of words in the current memory is not more than M-1, the software will save the new word to an unused memory unit; If the memory has been saved with m words, the software will empty the first word into memory, freeing up the unit to store the new word.

Suppose an English article has a length of n words. Given this article to be translated, how many dictionaries does the translation software need to external memory to find? Assume that there are no words in memory before the translation begins.

Input/output format

Input format:

Input file total 2 lines. Two numbers in each row are separated by a space.

The first behavior is two positive integers m and n, which represent the memory capacity and the length of the article.

The second behavior is n non-negative integers, in the order of the article, each number (size not more than 1000) represents an English word. The two words in the article are the same word, when and only if they correspond to the same nonnegative integer.

Output format:

Contains an integer number of times the software needs to look up the dictionary.

Input and Output Sample input example # #:
3 71 2 1 5 4 4 1
Sample # # of output:
5
Description

1s per test point

There is m=1,n≤5 for 10% of the data.

There is 0<=m<=100,0<=n<=1000 for 100% of the data.

The whole dictionary process is as follows: Each line represents the translation of a word, the memory status of the translation before the colon:

Empty: The initial state of the memory is empty.

1. 1: Find word 1 and dial into memory.

2. 1 2: Find the word 2 and transfer it into memory.

3. 1 2: Find the word 1 in memory.

4. 1 2 5: Find the word 5 and transfer it into memory.

5. 2 5 4: Find word 4 and dial in memory instead of Word 1.

6. 2 5 4: Find the word 4 in memory.

7. 5 4 1: Find word 1 and dial in memory instead of Word 2.

A total of 5 dictionaries were checked.

———————————————— I'm a split line ————————————————————————

This is a water problem ...

1#include <cstdio>2#include <iostream>3#include <cstring>4#include <queue>5 using namespacestd; 6deque<int>Mem; 7 intW; 8   9 intMain () {Ten     intM,n;  One     intans=0;  A     BOOLFlag;  -Cin>>m>>N;  -      for(intI=0; i<n; i++) {   theflag=true;  -scanf"%d",&W);  -          for(intj=0; J<mem.size (); J + +) {   -             if(mem[j]==W) { +flag=false;  -                  Break;  +             }   A         }   at         if(flag) { -             if(mem.size () = =m) { - Mem.pop_front ();  - Mem.push_back (W);  -ans++;  -}Else {   in Mem.push_back (W);  -ans++;  to             }   +         }   -     }   thecout<<ans;  *     return 0;  $}
View Code

NOIP2009 Improve group T3 machine translation Problem solving report-S.B.S

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.