zoukankan      html  css  js  c++  java
  • 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  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 a, b, c, d (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
    题解:水
     1 /******************************
     2 code by drizzle
     3 blog: www.cnblogs.com/hsd-/
     4 ^ ^    ^ ^
     5  O      O
     6 ******************************/
     7 #include<bits/stdc++.h>
     8 #include<iostream>
     9 #include<cstring>
    10 #include<cmath>
    11 #include<cstdio>
    12 #define ll long long
    13 #define mod 1000000007
    14 #define PI acos(-1.0)
    15 #define N 1000000000
    16 using namespace std;
    17 int a,b,c,d;
    18 int main()
    19 {
    20     scanf("%d %d %d %d",&a,&b,&c,&d);
    21     int s1=max(a/10*3,a-a/250*c);
    22     int s2=max(b/10*3,b-b/250*d);
    23     if(s1==s2)
    24     {
    25         cout<<"Tie"<<endl;
    26     }
    27     else
    28     {
    29         if(s1>s2)
    30         {
    31             cout<<"Misha"<<endl;
    32         }
    33         else
    34             cout<<"Vasya"<<endl;
    35     }
    36     return 0;
    37 }
    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的应用 注意细节

     1 /******************************
     2 code by drizzle
     3 blog: www.cnblogs.com/hsd-/
     4 ^ ^    ^ ^
     5  O      O
     6 ******************************/
     7 #include<bits/stdc++.h>
     8 #include<iostream>
     9 #include<cstring>
    10 #include<cmath>
    11 #include<cstdio>
    12 #define ll long long
    13 #define mod 1000000007
    14 #define PI acos(-1.0)
    15 #define N 1000000000
    16 using namespace std;
    17 map<int ,string> mp1;
    18 map<string,int> mp2;
    19 map<string,string> mp3;
    20 map<string,string> mp4;
    21 string str1,str2;
    22 int n;
    23 int main()
    24 {
    25     scanf("%d",&n);
    26     int jishu=0;
    27     for(int i=1;i<=n;i++)
    28     {
    29         cin>>str1>>str2;
    30         if(mp2[str1]==0)
    31         {
    32             mp1[jishu++]=str1;
    33             mp2[str1]=1;
    34             mp2[str2]=1;
    35             mp3[str1]=str2;
    36             mp4[str2]=str1;
    37         }
    38         else
    39         {
    40             mp3[mp4[str1]]=str2;
    41             mp4[str2]=mp4[str1];
    42             mp2[str1]=0;
    43             mp2[str2]=1;
    44         }
    45     }
    46     printf("%d
    ",jishu);
    47     for(int i=0;i<jishu;i++)
    48         cout<<mp1[i]<<" "<<mp3[mp1[i]]<<endl;
    49     return 0;
    50 }
    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

     1 /******************************
     2 code by drizzle
     3 blog: www.cnblogs.com/hsd-/
     4 ^ ^    ^ ^
     5  O      O
     6 ******************************/
     7 #include<bits/stdc++.h>
     8 #include<iostream>
     9 #include<cstring>
    10 #include<cmath>
    11 #include<cstdio>
    12 #define ll long long
    13 #define mod 1000000007
    14 #define PI acos(-1.0)
    15 using namespace std;
    16 struct node
    17 {
    18     int pos;
    19     int num;
    20     int sum;
    21     /*friend bool operator < (node aa,node bb)
    22     {
    23         return aa.num<bb.num;
    24     }
    25     */
    26 } N[70005];
    27 struct ans
    28 {
    29     int x,y;
    30 } NN[70005];
    31 queue<node> p;
    32 int n,vis[70005];
    33 int main()
    34 {
    35     scanf("%d",&n);
    36     for(int i=0; i<n; i++)
    37     {
    38         N[i].pos=i;
    39         scanf("%d %d",&N[i].num,&N[i].sum);
    40         if(N[i].num==1)
    41             p.push(N[i]);
    42     }
    43     int jishu=0;
    44     while(!p.empty())
    45     {
    46         node exm=p.front();
    47         p.pop();
    48         if(exm.num == 0 || vis[exm.pos]) continue;
    49 
    50         NN[++jishu].x=exm.sum;
    51         NN[jishu].y=exm.pos;
    52 
    53         N[exm.sum].num--;
    54         if(N[exm.sum].num == 0) vis[exm.sum] = 1;
    55         N[exm.sum].sum^=exm.pos;
    56 
    57         if(N[exm.sum].num==1)
    58             p.push(N[exm.sum]);
    59     }
    60     printf("%d
    ",jishu);
    61     for(int i=1; i<=jishu; i++)
    62         printf("%d %d
    ",NN[i].x,NN[i].y);
    63     return 0;
    64 }
     
  • 相关阅读:
    文件处理--文件操作
    三元运算
    alex 推荐的书
    python字符串、列表和字典的说明
    运算符
    while else语句
    格式化输出
    数据类型-元组
    数据类型-集合
    字符串
  • 原文地址:https://www.cnblogs.com/hsd-/p/5897722.html
Copyright © 2011-2022 走看看