• Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)


    A. Fraction
    time limit per test
    1 second
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction  is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).

    During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button ( + ) instead of division button (÷) and got sum of numerator and denominator that was equal to n instead of the expected decimal notation.

    Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction  such that sum of its numerator and denominator equals n. Help Petya deal with this problem.

    Input

    In the only line of input there is an integer n (3 ≤ n ≤ 1000), the sum of numerator and denominator of the fraction.

    Output

    Output two space-separated positive integers a and b, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.

    Examples
    input
    3
    output
    1 2
    input
    4
    output
    1 3
    input
    12
    output
    5 7

    找两个相近的数,使他们的和为n,gcd为1

    我想得分奇偶的贪心竟然错了,我发现我的有些没有得到结果,写丑了

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        int a,b;
        for(int i=n/2;i>0;i--)
        {
            if(__gcd(i,n-i)==1)
            {
                a=i;
                b=n-i;
                break;
            }
        }
        cout<<a<<" "<<b<<endl;
        return 0;
    }
    B. Maxim Buys an Apartment
    time limit per test
    1 second
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.

    Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly k already inhabited apartments, but he doesn't know their indices yet.

    Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.

    Input

    The only line of the input contains two integers: n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ n).

    Output

    Print the minimum possible and the maximum possible number of apartments good for Maxim.

    Example
    input
    6 3
    output
    1 3
    Note

    In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6are good.

     题意挺好理解,但是这样贪心的思路你不一定能想到,大概就是我一种是占前几个,或者交叉占

    卧槽,我的代码没有考虑特殊情况,赛后提交wa了一发

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        long long n,k;
        cin>>n>>k;
        long long a,b;
        if(k==n||k==0)
            a=0;
        else if(k)
            a=1;
        if(k!=n)b=min(k*2,n-k);
        else b=0;
        cout<<a<<" "<<b<<endl;
        return 0;
    }
    C. Planning
    time limit per test
    1 second
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day.

    Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created.

    All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so — their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule.

    Helen knows that each minute of delay of the i-th flight costs airport ci burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport.

    Input

    The first line contains two integers n and k (1 ≤ k ≤ n ≤ 300 000), here n is the number of flights, and k is the number of minutes in the beginning of the day that the flights did not depart.

    The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 107), here ci is the cost of delaying the i-th flight for one minute.

    Output

    The first line must contain the minimum possible total cost of delaying the flights.

    The second line must contain n different integers t1, t2, ..., tn (k + 1 ≤ ti ≤ k + n), here ti is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them.

    Example
    input
    5 2
    4 2 1 10 2
    output
    20
    3 6 7 4 5
    Note

    Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)·4 + (4 - 2)·2 + (5 - 3)·1 + (6 - 4)·10 + (7 - 5)·2 = 38 burles.

    However, the better schedule is shown in the sample answer, its cost is (3 - 1)·4 + (6 - 2)·2 + (7 - 3)·1 + (4 - 4)·10 + (5 - 5)·2 = 20 burles.

     这个贪心就是先把1~k+1放进去,然后选择大的出列,然后继续加入,出列

    这个我中途爆了LL,贼恐怖

    #include<bits/stdc++.h>
    using namespace std;
    const int N=300005;
    priority_queue<pair<int,int> >Q;
    vector<int>V(N);
    int main()
    {
        long long ans=0;
        int n,k;
        scanf("%d%d",&n,&k);
        for(int i=1;i<=k;i++)
        {
            int x;
            scanf("%d",&x);
            Q.push(make_pair(x,i));
        }
        for(int i=k+1;i<=n;i++)
        {
            int x;
            scanf("%d",&x);
            Q.push(make_pair(x,i));
            int b=Q.top().second;
            int c=Q.top().first;
            Q.pop();
            ans+=1LL*(i-b)*c;
            V[b]=i;
        }
        int i=n+1;
        while(!Q.empty())
        {
            int b=Q.top().second;
            int c=Q.top().first;
            Q.pop();
            ans+=1LL*(i-b)*c;
            V[b]=i;
            i++;
        }
        printf("%lld
    ",ans);
        for(int i=1;i<=n;i++)
            printf("%d ",V[i]);
        return 0;
    }
  • 相关阅读:
    记录vue
    vue记录
    布局例子
    element ui + vue.js + asp.net mvc 实现单页面程序——使用 ASP.NET Core MVC 生成 Web API 和 Web UI——(20220818)
    标准index.html模板
    开发记录
    HelloWorld.vue
    Vue+ElementUI+.netcore前后端分离框架开发项目——项目开发记录20220816——使用 ASP.NET Core MVC 生成 Web API 和 Web UI
    script笔记1
    基于elementui 动态换肤的代码详解
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7487931.html
Copyright © 2020-2023  润新知