Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

A. Contest
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 t minutes after the contest started, you get Codeforces Round #285 (Div. 2) A B C 模拟 stl  拓扑排序 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 ≤ 3500, 0 ≤ 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.

Examples
input
500 1000 20 30
output
Vasya
input
1000 1000 1 1
output
Tie
input
1500 1000 176 177
output
Misha

题意:根据公式计算得分 输出得分较高的 相同时输出Tie
题解:水
 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#define ll long long
#define mod 1000000007
#define PI acos(-1.0)
#define N 1000000000
using namespace std;
int a,b,c,d;
int main()
{
scanf("%d %d %d %d",&a,&b,&c,&d);
int s1=max(a/*,a-a/*c);
int s2=max(b/*,b-b/*d);
if(s1==s2)
{
cout<<"Tie"<<endl;
}
else
{
if(s1>s2)
{
cout<<"Misha"<<endl;
}
else
cout<<"Vasya"<<endl;
}
return ;
}
B. Misha and Changing Handles
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 handle newis 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.

Examples
input
5
Misha ILoveCodeforces
Vasya Petrov
Petrov VasyaPetrov123
ILoveCodeforces MikeMirzayanov
Petya Ivanov
output
3
Petya Ivanov
Misha MikeMirzayanov
Vasya VasyaPetrov123

题意:给你q个更改 (old,new) 输出所有的通过传递后的最后的更改结果(old,new)

题解:stl的应用 注意细节

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#define ll long long
#define mod 1000000007
#define PI acos(-1.0)
#define N 1000000000
using namespace std;
map<int ,string> mp1;
map<string,int> mp2;
map<string,string> mp3;
map<string,string> mp4;
string str1,str2;
int n;
int main()
{
scanf("%d",&n);
int jishu=;
for(int i=;i<=n;i++)
{
cin>>str1>>str2;
if(mp2[str1]==)
{
mp1[jishu++]=str1;
mp2[str1]=;
mp2[str2]=;
mp3[str1]=str2;
mp4[str2]=str1;
}
else
{
mp3[mp4[str1]]=str2;
mp4[str2]=mp4[str1];
mp2[str1]=;
mp2[str2]=;
}
}
printf("%d\n",jishu);
for(int i=;i<jishu;i++)
cout<<mp1[i]<<" "<<mp3[mp1[i]]<<endl;
return ;
}
C. Misha and Forest
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the second integer is the XOR sum of the numbers of vertices adjacent to v (if there were no adjacent vertices, he wrote down 0).

Next day Misha couldn't remember what graph he initially had. Misha has values degreev and sv left, though. Help him find the number of edges and the edges of the initial graph. It is guaranteed that there exists a forest that corresponds to the numbers written by Misha.

Input

The first line contains integer n (1 ≤ n ≤ 216), the number of vertices in the graph.

The i-th of the next lines contains numbers degreei and si (0 ≤ degreei ≤ n - 1, 0 ≤ si < 216), separated by a space.

Output

In the first line print number m, the number of edges of the graph.

Next print m lines, each containing two distinct numbers, a and b (0 ≤ a ≤ n - 1, 0 ≤ b ≤ n - 1), corresponding to edge (a, b).

Edges can be printed in any order; vertices of the edge can also be printed in any order.

Examples
input
3
2 3
1 0
1 0
output
2
1 0
2 0
input
2
1 1
1 0
output
1
0 1
Note

The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".

题意:给你n个点  每个点有两个值  num个点与当前点相连 相连的点的序号的异或和为sum 要求输出所有的边 u-v

题解:将所有的num值为1的点入队  不断的出队更新 标记已经入队的点

(存在那种对 已经在队列中的点 的更新) 标记处理

数据

2

1 0

1 1

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#define ll long long
#define mod 1000000007
#define PI acos(-1.0)
using namespace std;
struct node
{
int pos;
int num;
int sum;
/*friend bool operator < (node aa,node bb)
{
return aa.num<bb.num;
}
*/
} N[];
struct ans
{
int x,y;
} NN[];
queue<node> p;
int n,vis[];
int main()
{
scanf("%d",&n);
for(int i=; i<n; i++)
{
N[i].pos=i;
scanf("%d %d",&N[i].num,&N[i].sum);
if(N[i].num==)
p.push(N[i]);
}
int jishu=;
while(!p.empty())
{
node exm=p.front();
p.pop();
if(exm.num == || vis[exm.pos]) continue; NN[++jishu].x=exm.sum;
NN[jishu].y=exm.pos; N[exm.sum].num--;
if(N[exm.sum].num == ) vis[exm.sum] = ;
N[exm.sum].sum^=exm.pos; if(N[exm.sum].num==)
p.push(N[exm.sum]);
}
printf("%d\n",jishu);
for(int i=; i<=jishu; i++)
printf("%d %d\n",NN[i].x,NN[i].y);
return ;
}
 
上一篇:Construction of Primitives in Open Cascade


下一篇:HDU 2896 (AC自动机模板题)