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 (0≤n≤6) — 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 (0≤m≤6) — 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

4redpurpleyelloworange

output

Copy

2SpaceTime

input

Copy

0

output

Copy

6TimeSpacePowerRealityMindSoul

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\n",6-m);
    set<string>::iterator it;
    for(it=s.begin(); it!=s.end(); it++)
    {
        cout<<*it<<endl;
    }
}

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 (1≤x,y≤109).

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=5?5?5?5?5?5?5?5=39062558=5?5?5?5?5?5?5?5=390625, and 85=8?8?8?8?8=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 ("=")

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 (3≤n≤3000) — the number of displays.

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

The third line contains nn integers c1,c2,…,cn (1≤ci≤108) — 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

52 4 5 4 1040 30 20 10 40

output

Copy

90

input

Copy

3100 101 1002 4 5

output

Copy

-1

input

Copy

101 2 3 4 5 6 7 8 9 1010 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\n");
    else cout<<ans<<endl;
}

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, k, s in the first line of input (1≤n≤105, 0≤m≤105, 1≤s≤k≤min(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(1≤ai≤k), 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 uu vv (1≤u,v≤n u≠v) — 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 31 2 4 3 21 22 33 44 14 5

output

Copy

2 2 2 2 3 

input

Copy

7 6 3 21 2 3 3 2 2 11 22 33 42 55 66 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);
    }

}

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 (103≤n≤106).

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

52 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");
    }

}

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

原文地址:https://www.cnblogs.com/MengX/p/9112745.html

时间: 2024-08-30 01:13:10

Codeforces Round #485 (Div. 2)的相关文章

Codeforces Round #485 (Div. 2) E. Petr and Permutations

Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/problem/E Description Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to gene

Codeforces Round #485 (Div. 2) D. Fair

Codeforces Round #485 (Div. 2) D. Fair 题目连接: http://codeforces.com/contest/987/problem/D Description Some company is going to hold a fair in Byteland. There are $n$ towns in Byteland and $m$ two-way roads between towns. Of course, you can reach any t

【思维】Codeforces Round #485 (Div. 2) B. High School: Become Human(对数)

题目链接:http://codeforces.com/contest/987/problem/B 在运算的时候取对数就好了 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 #define ll long long 6 #define eps 1e-6 7 8 int main() 9 { 10 ll x,y; 11 double xx; 12 scanf("%lld %lld",&x,&y);

Codeforces Round #485 (Div. 2) C Three displays

C. Three displays 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

Codeforces Round #485 (Div. 2)-B-High School: Become Human

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 ha

Codeforces Round #485 Div. 1 vp记

A:对每种商品多源bfs一下每个点到该商品的最近距离,对每个点sort一下取前s个即可. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define int long long #d

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我