zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 38 (Rated for Div. 2)

    这场打了小号

    A. Word Correction
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.

    Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.

    You are given a word s. Can you predict what will it become after correction?

    In this problem letters a, e, i, o, u and y are considered to be vowels.

    Input

    The first line contains one integer n (1 ≤ n ≤ 100) — the number of letters in word s before the correction.

    The second line contains a string s consisting of exactly n lowercase Latin letters — the word before the correction.

    Output

    Output the word s after the correction.

    Examples
    input
    Copy
    5
    weird
    output
    werd
    input
    Copy
    4
    word
    output
    word
    input
    Copy
    5
    aaeaa
    output
    a
    Note

    Explanations of the examples:

    1. There is only one replace: weird  werd;
    2. No replace needed since there are no two consecutive vowels;
    3. aaeaa  aeaa  aaa  aa  a.

     连续的两个原因字母或y就保留第一个字母

    #include<bits/stdc++.h>
    using namespace std;
    const int N=2005;
    int main()
    {
        ios::sync_with_stdio(false);
        string s,t;
        int n;
        cin>>n>>s;
        set<char>S;
        S.insert('a'),S.insert('e'),S.insert('i'),S.insert('o'),S.insert('u'),S.insert('y');
        while(true)
        {
            int f=1;
            for(int i=1;s[i]&&f;i++)
            {
                if(S.count(s[i-1])&&S.count(s[i]))
                {
                    f=0;
                    t=s.substr(0,i)+s.substr(i+1);
                }
            }
            if(f)break;
            s=t;
        }
        cout<<s;
        return 0;
    }
    B. Run For Your Prize
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You and your friend are participating in a TV show "Run For Your Prize".

    At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.

    You know that it takes exactly 1 second to move from position x to position x + 1 or x - 1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.

    Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.

    What is the minimum number of seconds it will take to pick up all the prizes?

    Input

    The first line contains one integer n (1 ≤ n ≤ 105) — the number of prizes.

    The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 106 - 1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.

    Output

    Print one integer — the minimum number of seconds it will take to collect all prizes.

    Examples
    input
    Copy
    3
    2 3 9
    output
    8
    input
    Copy
    2
    2 999995
    output
    5
    Note

    In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.

    In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.

    有n个东西,你可以把x位置的移到x+1或x-1,你在位置1你的朋友在位置1e6

    其实就是求一下到两点距离的最小距离中的最大距离

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        ios::sync_with_stdio(false);
        int n,ans=0;
        cin>>n;
        for(int i=0,x;i<n;i++)
            cin>>x,ans=max(ans,min(x-1,1000000-x));
        cout<<ans;
        return 0;
    }
    C. Constructing Tests
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Let's denote a m-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size m × m of this matrix contains at least one zero.

    Consider the following problem:

    You are given two integers n and m. You have to construct an m-free square matrix of size n × n such that the number of 1's in this matrix is maximum possible. Print the maximum possible number of 1's in such matrix.

    You don't have to solve this problem. Instead, you have to construct a few tests for it.

    You will be given t numbers x1, x2, ..., xt. For every , find two integers ni and mi (ni ≥ mi) such that the answer for the aforementioned problem is exactly xi if we set n = ni and m = mi.

    Input

    The first line contains one integer t (1 ≤ t ≤ 100) — the number of tests you have to construct.

    Then t lines follow, i-th line containing one integer xi (0 ≤ xi ≤ 109).

    Note that in hacks you have to set t = 1.

    Output

    For each test you have to construct, output two positive numbers ni and mi (1 ≤ mi ≤ ni ≤ 109) such that the maximum number of 1's in a mi-free ni × ni matrix is exactly xi. If there are multiple solutions, you may output any of them; and if this is impossible to construct a test, output a single integer  - 1.

    Example
    input
    Copy
    3
    21
    0
    1
    output
    5 2
    1 1
    -1

     这个题目其实并不难,硬生生让我搞成了难题

    是一个m*m的01的矩阵,其中n*n的矩阵中至少有一个为1,最后剩下的大小为x

    所以就是一个公式,并不用猜

    总大小m*m,少的个数(m/n)^2,即m*m-(m/n)^2=x

    枚举m就行了,求m/n

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int T;
        cin>>T;
        while(T--)
        {
            
            scanf("%d",&x);
            f=0;
            for (i=0; i<4e4; i++)
                if ((a=i*i-x)>0)
                    if ((b=sqrt(a))*b==a)
                        if (i/b>i/(b+1))
                        {
                            printf("%d %d
    ",i,i/b);
                            f=1;
                            break;
                        }
            if (!f) puts("-1");
        }
    }
     
    D. Buy a Ticket
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well.

    There are n cities in Berland. People can travel between cities using two-directional train routes; there are exactly m routes, i-th route can be used to go from city vi to city ui (and from ui to vi), and it costs wi coins to use this route.

    Each city will be visited by "Flayer", and the cost of the concert ticket in i-th city is ai coins.

    You have friends in every city of Berland, and they, knowing about your programming skills, asked you to calculate the minimum possible number of coins they have to pay to visit the concert. For every city i you have to compute the minimum number of coins a person from city i has to spend to travel to some city j (or possibly stay in city i), attend a concert there, and return to city i (if j ≠ i).

    Formally, for every  you have to calculate , where d(i, j) is the minimum number of coins you have to spend to travel from city i to city j. If there is no way to reach city j from city i, then we consider d(i, j) to be infinitely large.

    Input

    The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 2·105).

    Then m lines follow, i-th contains three integers viui and wi (1 ≤ vi, ui ≤ n, vi ≠ ui1 ≤ wi ≤ 1012) denoting i-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each (v, u) neither extra (v, u) nor (u, v) present in input.

    The next line contains n integers a1, a2, ... ak (1 ≤ ai ≤ 1012) — price to attend the concert in i-th city.

    Output

    Print n integers. i-th of them must be equal to the minimum number of coins a person from city i has to spend to travel to some city j (or possibly stay in city i), attend a concert there, and return to city i (if j ≠ i).

    Examples
    input
    Copy
    4 2
    1 2 4
    2 3 7
    6 20 1 25
    output
    6 14 1 25 
    input
    Copy
    3 3
    1 2 1
    2 3 1
    1 3 1
    30 10 20
    output
    12 10 12 

     这个D其实是一个图论题,关键在于建图。spfa会被卡的

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<ll,ll> pll;
    const int N=2e5+5;
    priority_queue<pll>pq;
    vector<pll>G[N];
    ll dp[N],n,m,a,b,x;
    int main()
    {
        cin>>n>>m;
        for(int i=0; i<m; i++)
            cin>>a>>b>>x,G[a].push_back(pll(b,2*x)),G[b].push_back(pll(a,2*x));
        for(int i=1; i<=n; i++)cin>>dp[i],pq.push(pll(-dp[i],i));
        while(!pq.empty())
        {
            ll u=pq.top().second,val=-pq.top().first;
            pq.pop();
            if(val!=dp[u])continue;
            for(auto X:G[u])
            {
                ll v=X.first,w=X.second;
                if(dp[v]>dp[u]+w)dp[v]=dp[u]+w,pq.push(pll(-dp[v],v));
            }
        }
        for(int i=1; i<=n; i++)cout<<dp[i]<<" ";
        return 0;
    }
  • 相关阅读:
    2020软件工程作业02
    自我介绍
    Requests的使用
    爬虫基本原理
    2019春总结作业
    十二周作业
    十一周作业
    第十周作业
    intellij idea 的全局搜索快捷键方法
    Oracle多表关联
  • 原文地址:https://www.cnblogs.com/BobHuang/p/8457703.html
Copyright © 2011-2022 走看看