• Codeforces Round #485 (Div. 2)


    A. Infinity Gauntlet
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:

    • the Power Gem of purple color,
    • the Time Gem of green color,
    • the Space Gem of blue color,
    • the Soul Gem of orange color,
    • the Reality Gem of red color,
    • the Mind Gem of yellow color.

    Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.

    Input

    In the first line of input there is one integer nn (0n6) — the number of Gems in Infinity Gauntlet.

    In next nn lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.

    Output

    In the first line output one integer mm (0m6) — the number of absent Gems.

    Then in mm lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.

    Examples
    input
    Copy
    4
    red
    purple
    yellow
    orange
    output
    Copy
    2
    Space
    Time
    input
    Copy
    0
    output
    Copy
    6
    Time
    Space
    Power
    Reality
    Mind
    Soul
    Note

    In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.

    In the second sample Thanos doesn't have any Gems, so he needs all six.

     题意:6种石头对应六中颜色,然后输入颜色,求没出现的颜色对应的石头

    直接set处理下

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    map<string,string> mp;
    int main()
    {
        int n;
        set<string> s;
        string p;
        mp["purple"]="Power";
        mp["green"]="Time";
        mp["blue"]="Space";
        mp["orange"]="Soul";
        mp["red"]="Reality";
        mp["yellow"]="Mind";
        map<string,string>::iterator ip;
        for(ip=mp.begin();ip!=mp.end();ip++)
        {
            s.insert(ip->second);
        }
        scanf("%d",&n);
        int m=n;
        while(n--)
        {
            cin>>p;
            s.erase(mp[p]);
        }
        printf("%d
    ",6-m);
        set<string>::iterator it;
        for(it=s.begin(); it!=s.end(); it++)
        {
            cout<<*it<<endl;
        }
    }
    View Code
    B. High School: Become Human
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.

    It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.

    One of the popular pranks on Vasya is to force him to compare x with yx. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.

    Please help Vasya! Write a fast program to compare xy with yx for Vasya, maybe then other androids will respect him.

    Input

    On the only line of input there are two integers xx and yy (1x,y109).

    Output

    If xy<yx, then print '<' (without quotes). If xy>yx, then print '>' (without quotes). If xy=yx, then print '=' (without quotes).

    Examples
    input
    Copy
    5 8
    output
    Copy
    >
    input
    Copy
    10 3
    output
    Copy
    <
    input
    Copy
    6 6
    output
    Copy
    =
    Note

    In the first example 58=55555555=39062558=5⋅5⋅5⋅5⋅5⋅5⋅5⋅5=390625, and 85=88888=3276885=8⋅8⋅8⋅8⋅8=32768. So you should print '>'.

    In the second example 103=1000<310=59049103=1000<310=59049.

    In the third example 66=46656=6666=46656=66.

    题意:求x的y次和y的x次大小

    直接判断log(x)*y与log(y)*x大小就行 我用python搞的emmm

    import math
    a,b=map(int,input().split())
    aaa = b*math.log(a)
    bbb = a*math.log(b)
    if aaa>bbb:
        print ('>')
    elif aaa<bbb:
        print ('<')
    else :
        print ("=")
    View Code
    C. Three displays
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.

    There are nn displays placed along a road, and the ii-th of them can display a text with font size sisi only. Maria Stepanovna wants to rent such three displays with indices i<j<ki<j<k that the font size increases if you move along the road in a particular direction. Namely, the condition si<sj<sksi<sj<sk should be held.

    The rent cost is for the ii-th display is cici. Please determine the smallest cost Maria Stepanovna should pay.

    Input

    The first line contains a single integer nn (3n3000) — the number of displays.

    The second line contains nn integers s1,s2,,sn(1si109) — the font sizes on the displays in the order they stand along the road.

    The third line contains nn integers c1,c2,,cn (1ci108) — the rent costs for each display.

    Output

    If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i<j<ki<j<k such that si<sj<sksi<sj<sk.

    Examples
    input
    Copy
    5
    2 4 5 4 10
    40 30 20 10 40
    output
    Copy
    90
    input
    Copy
    3
    100 101 100
    2 4 5
    output
    Copy
    -1
    input
    Copy
    10
    1 2 3 4 5 6 7 8 9 10
    10 13 11 14 15 12 13 13 18 13
    output
    Copy
    33
    Note

    In the first example you can, for example, choose displays 11, 44 and 55, because s1<s4<s5(2<4<102<4<10), and the rent cost is 40+10+40=9040+10+40=90.

    In the second example you can't select a valid triple of indices, so the answer is -1.

     题意:输入n个数以及n个数的价值,然后求三个si递增的串,且ci和最小。

    先确定第三位数dp[j]表示s[j]后面能取值最小的。

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    ll a[5000],b[5000],dp[5000];
    const int maxn=1e9+10;
    int main()
    {
        int n;
        scanf("%d",&n);
        for(int i=1; i<=n; i++)
            scanf("%I64d",&a[i]);
        for(int i=1; i<=n; i++)
            scanf("%I64d",&b[i]);
        for(int i=1; i<=n; i++)
        {
            ll mn=maxn;
            for(int j=i+1; j<=n; j++)
            {
                if(a[i]<a[j])
                {
                    mn=min(mn,b[j]);
                }
            }
            dp[i]=mn;
        }
        ll ans=maxn;
        for(int i=1; i<=n; i++)
        {
            for(int j=i+1; j<=n; j++)
            {
                if(a[i]<a[j])
                {
                    if(dp[j]!=maxn)
                        ans=min(ans,b[i]+b[j]+dp[j]);
                }
            }
        }
        if(ans==maxn) printf("-1
    ");
        else cout<<ans<<endl;
    }
    View Code
    D. Fair
    time limit per test
    2 seconds
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    Some company is going to hold a fair in Byteland. There are nn towns in Byteland and mm two-way roads between towns. Of course, you can reach any town from any other town using roads.

    There are kk types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least ssdifferent types of goods. It costs d(u,v)d(u,v) coins to bring goods from town uu to town vv where d(u,v)d(u,v) is the length of the shortest path from uuto vv. Length of a path is the number of roads in this path.

    The organizers will cover all travel expenses but they can choose the towns to bring goods from. Now they want to calculate minimum expenses to hold a fair in each of nn towns.

    Input

    There are 4 integers n, m, ks in the first line of input (1n1050m1051skmin(n,100)) — the number of towns, the number of roads, the number of different types of goods, the number of different types of goods necessary to hold a fair.

    In the next line there are nn integers a1,a2,,an(1aik), where aiai is the type of goods produced in the ii-th town. It is guaranteed that all integers between 11 and kk occur at least once among integers aiai.

    In the next mm lines roads are described. Each road is described by two integers uvv (1u,vn uv) — the towns connected by this road. It is guaranteed that there is no more than one road between every two towns. It is guaranteed that you can go from any town to any other town via roads.

    Output

    Print nn numbers, the ii-th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town ii. Separate numbers with spaces.

    Examples
    input
    Copy
    5 5 4 3
    1 2 4 3 2
    1 2
    2 3
    3 4
    4 1
    4 5
    output
    Copy
    2 2 2 2 3 
    input
    Copy
    7 6 3 2
    1 2 3 3 2 2 1
    1 2
    2 3
    3 4
    2 5
    5 6
    6 7
    output
    Copy
    1 1 1 2 2 1 1 
    Note

    Let's look at the first sample.

    To hold a fair in town 1 you can bring goods from towns 1 (0 coins), 2 (1 coin) and 4 (1 coin). Total numbers of coins is 2.

    Town 2: Goods from towns 2 (0), 1 (1), 3 (1). Sum equals 2.

    Town 3: Goods from towns 3 (0), 2 (1), 4 (1). Sum equals 2.

    Town 4: Goods from towns 4 (0), 1 (1), 5 (1). Sum equals 2.

    Town 5: Goods from towns 5 (0), 4 (1), 3 (2). Sum equals 3.

     题意:n个城镇,m条路(无向图),k种货物,每次举办活动需要s种货物。

    按每种货物bfs,到每个城镇的最短路,然后排序,求最短的s条和即可。

    #include<bits/stdc++.h>
    #include<cmath>
    #define ll long long
    using namespace std;
    const int maxn=100010;
    const int INF = 0x3f3f3f3f;
    int a[maxn],dis[110][maxn],n;
    int head[maxn],To[maxn*200],Next[maxn*200],cnt,d[maxn];
    void add(int u,int v)
    {
        Next[++cnt]=head[u];
        head[u]=cnt;
        To[cnt]=v;
    }
    void bfs(int x)
    {
        queue<int> q;
        for(int i=1; i<=n; i++)
            if(a[i]==x)
            {
                q.push(i);
                dis[x][i]=0;
            }
        while(!q.empty())
        {
            int v=q.front();
            q.pop();
            for(int i=head[v]; i; i=Next[i])
            {
                if(dis[x][To[i]]>dis[x][v]+1)
                {
                    dis[x][To[i]]=dis[x][v]+1;
                    q.push(To[i]);
                }
            }
        }
    
    }
    int main()
    {
        int m,k,s,u,v;
        scanf("%d %d %d %d",&n,&m,&k,&s);
        for(int i=1; i<=n; i++) scanf("%d",&a[i]);
        memset(dis,INF,sizeof(dis));
        while(m--)
        {
            scanf("%d %d",&u,&v);
            add(u,v);
            add(v,u);
        }
        for(int i=1; i<=k; i++) bfs(i);
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=k; j++)
                d[j]=dis[j][i];
            sort(d+1,d+1+k);
            int res=0;
            for(int j=1; j<=s; j++)
                res+=d[j];
            printf("%d ",res);
        }
    
    }
    View Code
    E. Petr and Permutations
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from 11 to nn and then 3n3n times takes a random pair of different elements and swaps them. Alex envies Petr and tries to imitate him in all kind of things. Alex has also come up with a problem about random permutation.

    He generates a random permutation just like Petr but swaps elements 7n+1times instead of 3n times. Because it is more random, OK?!

    You somehow get a test from one of these problems and now you want to know from which one.

    Input

    In the first line of input there is one integer n (103n106).

    In the second line there are nn distinct integers between 1 and n — the permutation of size nn from the test.

    It is guaranteed that all tests except for sample are generated this way: First we choose nn — the size of the permutation. Then we randomly choose a method to generate a permutation — the one of Petr or the one of Alex. Then we generate a permutation using chosen method.

    Output

    If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).

    Example
    input
    Copy
    5
    2 4 5 1 3
    output
    Copy
    Petr
    Note

    Please note that the sample is not a valid test (because of limitations for n) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC.

    Due to randomness of input hacks in this problem are forbidden.

     题意:给出一个长度为n的序列,原始序列应该是1 2 3 4 ...n ,但是被打乱了,Petr打乱的次数3n倍,Um_nik是7n+1.

    因为7n+1与3n奇偶性不同,求出最小交换次数,判断就行。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<ctime>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    #include<string>
    using namespace std;
    const int maxn=1000010;
    int n,pos[maxn],a[maxn];
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%d",&a[i]),pos[a[i]]=i;
        int cnt=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]!=i)
            {
                int j=pos[i];
                swap(a[i],a[j]);
                pos[a[i]]=i;
                pos[a[j]]=j;
                cnt++;
            }
        }
        if(n%2==0)
        {
            if(cnt%2==0)
            printf("Petr");
            else printf("Um_nik");
        }
        else
        {
            if(cnt%2)
                printf("Petr");
            else printf("Um_nik");
        }
    
    }
    View Code

    PS:摸鱼怪的博客分享,欢迎感谢各路大牛的指点~

  • 相关阅读:
    今日进度
    今日进度
    每周总结
    今日进度
    今日进度
    今日进度
    flask展示Excel
    ubuntu 相关
    python解析xml三种方法【ElementTree】【DOM】【SAX】
    Lambda实现if...elif...else【三元表达式】
  • 原文地址:https://www.cnblogs.com/MengX/p/9112745.html
Copyright © 2020-2023  润新知