codeforces#285 A - Contest + B - Misha and Changing Handles

A - Contest
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit  Status

Description

Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs a points and Vasya solved the problem that costs b points. Besides, Misha submitted the problem c minutes after the contest started and Vasya submitted the problem d minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs p points tminutes after the contest started, you get  points.

Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth.

Input

The first line contains four integers abcd (250 ≤ a, b ≤ 35000 ≤ c, d ≤ 180).

It is guaranteed that numbers a and b are divisible by 250 (just like on any real Codeforces round).

Output

Output on a single line:

"Misha" (without the quotes), if Misha got more points than Vasya.

"Vasya" (without the quotes), if Vasya got more points than Misha.

"Tie" (without the quotes), if both of them got the same number of points.

Sample Input

Input
500 1000 20 30
Output
Vasya
Input
1000 1000 1 1
Output
Tie
Input
1500 1000 176 177
Output
Misha

按公式比较两人的得分

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
int main()
{
    int a , b , c , d , k1 , k2 ;
    scanf("%d %d %d %d", &a, &b, &c, &d) ;
    k1 = max( 3*a/10,a-a*c/250 ) ;
    k2 = max( 3*b/10,b-b*d/250 ) ;
    if( k1 > k2 )
        printf("Misha\n") ;
    else if( k2 > k1 )
        printf("Vasya\n") ;
    else
        printf("Tie\n");
    return 0 ;
}


B - Misha and Changing Handles
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit  Status

Description

Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.

Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.

Input

The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests.

Next q lines contain the descriptions of the requests, one per line.

Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20.

The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handlenew is not used and has not been used by anyone.

Output

In the first line output the integer n — the number of users that changed their handles at least once.

In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old andnew, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order.

Each user who changes the handle must occur exactly once in this description.

Sample Input

Input
5
Misha ILoveCodeforces
Vasya Petrov
Petrov VasyaPetrov123
ILoveCodeforces MikeMirzayanov
Petya Ivanov
Output
3
Petya Ivanov
Misha MikeMirzayanov
Vasya VasyaPetrov123

更改名字,更改的名字不能是正在使用的,显示最后的名字映射。

Map给出每个名字的编号,记录下每一次出现的名字,p,q两个数组对应指向对方代表是一对映射。

#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
using namespace std ;
map <string,int> Map ;
char str[2200][22] ;
int p[2200] , q[2200] ;
int main()
{
    int num , n , k1 , k2 , cnt ;
    char s1[22] , s2[22] ;
    while( scanf("%d", &n) != EOF )
    {
        memset(p,0,sizeof(p)) ;
        memset(q,0,sizeof(q)) ;
        cnt = 1 ;
        num = 0 ;
        while( n-- )
        {
            scanf("%s %s", s1, s2) ;
            if( Map[s2] > 0 )
                continue ;
            if( (k1 = Map[s1]) > 0 )
            {
                Map[s1] = 0 ;
                strcpy(str[cnt++],s2) ;
                p[ q[k1] ] = cnt-1 ;
                q[cnt-1] = q[k1] ;
                Map[s2] = cnt-1 ;
            }
            else
            {
                strcpy(str[cnt++],s1) ;
                strcpy(str[cnt++],s2) ;
                p[cnt-2] = cnt-1 ;
                q[cnt-1] = cnt-2 ;
                Map[s2] = cnt-1 ;
                num++ ;
            }
        }
        printf("%d\n", num) ;
        int i ;
        for(i = 0 ; i < cnt ; i++)
            if( p[i] )
                printf("%s %s\n", str[i], str[ p[i] ]) ;
    }
    return 0 ;
}


你可能感兴趣的:(codeforces#285 A - Contest + B - Misha and Changing Handles)