Codeforces Round #284 (Div. 2)(二)

2015-01-22 21:09:03 · 作者: · 浏览: 13
ill be recorded in your notes.

Input

The first line contains two integers, n and m (1?≤?n?≤?3000, 1?≤?m?≤?3000) — the number of words in the professor's lecture and the number of words in each of these languages.

The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.

The next line contains n space-separated strings c1,?c2,?...,?cn — the text of the lecture. It is guaranteed that each of the strings cibelongs to the set of strings {a1,?a2,?... am}.

All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.

Output

Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.

Sample test(s) input
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
output
codeforces round letter round
input
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
output
hbnyiyc joll joll un joll

#include 
    
     
#include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           #include 
          
            #include 
           
             #include 
            
              #include
              using namespace std; struct { char s[10000]; char e[10000]; }p[10000]; int main() { int n, m; while (scanf(%d %d, &n, &m) != EOF) { for (int i = 1; i <= m; i++) { scanf(%s %s,p[i].s,p[i].e); int l1 = strlen(p[i].s); int l2 = strlen(p[i].e); if (l1 > l2) { char c[10000]; strcpy(c,p[i].s); strcpy(p[i].s, p[i].e); strcpy(p[i].e, c); } } for (int i = 1; i <= n; i++) { char c[10000]; scanf(%s,c); for (int j = 1; j <= m; j++) { if ( !strcmp(p[j].e, c) || !strcmp(p[j].s, c)) { if (i == n) { printf(%s , p[j].s); } else { printf(%s ,p[j].s); } break; } } } } return 0; }
            
           
          
         
        
       
      
     
    


?

?

C

?

C. Crazy Town time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix?+?biy?+?ci?=?0, where ai and biare not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.

Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).

Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.

Input

The first line contains two space-separated integers x1, y1 (?-?106?≤?x1,?y1?≤?106) — the coordinates of your home.

The second line contains two integers separated by a space x2, y2 (?-?106?≤?x2,?y2?≤?106) — the coordinates of the university you are studying at.

The third line contains an integer n (1?≤?n?≤?300) — the number of roads in the city. The following n lines contain 3 space-separated integers (?-?106?≤?ai,?bi,?ci?≤?106; |ai|?+?|bi|?>?0) — the coefficients of the line aix?+?biy?+?ci?=?0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).

Output

Output the answer to the problem.

Sample test(s) input
1 1
-1 -1
2
0 1 0
1 0 0
output
2
input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
output
2
Note

Pictures to the samples are present