• 大笑三声再往下看!


    这是可怕的第一篇博客!

    可怕感谢各位小哥哥小姐姐前来捧场~

    给大家分享昨天我补的最有价值的三道题:

    这是昨天的一篇博客,但是太凉了就没发出来,今天补了好几道有价值的明天如果心情好就发出来。

    B - Polycarp's Practice

    Polycarp is practicing his problem solving skill. He has a list of nn problems with difficulties a1,a2,,ana1,a2,…,an, respectively. His plan is to practice for exactly kk days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cannot skip any problem from his list. He has to solve all nn problems in exactly kk days.

    Thus, each day Polycarp solves a contiguous sequence of (consecutive) problems from the start of the list. He can't skip problems or solve them multiple times. As a result, in kk days he will solve all the nn problems.

    The profit of the jj-th day of Polycarp's practice is the maximum among all the difficulties of problems Polycarp solves during the jj-th day (i.e. if he solves problems with indices from ll to rr during a day, then the profit of the day is maxliraimaxl≤i≤rai). The total profit of his practice is the sum of the profits over all kk days of his practice.

    You want to help Polycarp to get the maximum possible total profit over all valid ways to solve problems. Your task is to distribute all nn problems between kk days satisfying the conditions above in such a way, that the total profit is maximum.

    For example, if n=8,k=3n=8,k=3 and a=[5,4,2,6,5,1,9,2]a=[5,4,2,6,5,1,9,2], one of the possible distributions with maximum total profit is: [5,4,2],[6,5],[1,9,2][5,4,2],[6,5],[1,9,2]. Here the total profit equals 5+6+9=205+6+9=20.

    Input

    The first line of the input contains two integers nn and kk (1kn20001≤k≤n≤2000) — the number of problems and the number of days, respectively.

    The second line of the input contains nn integers a1,a2,,ana1,a2,…,an (1ai20001≤ai≤2000) — difficulties of problems in Polycarp's list, in the order they are placed in the list (i.e. in the order Polycarp will solve them).

    Output

    In the first line of the output print the maximum possible total profit.

    In the second line print exactly kk positive integers t1,t2,,tkt1,t2,…,tk (t1+t2++tkt1+t2+⋯+tkmust equal nn), where tjtj means the number of problems Polycarp will solve during the jj-th day in order to achieve the maximum possible total profit of his practice.

    If there are many possible answers, you may print any of them.

    Examples

    Input
    8 3
    5 4 2 6 5 1 9 2
    Output
    20
    3 2 3
    Input
    5 1
    1 1 1 1 1
    Output
    1
    5
    Input
    4 2
    1 2000 2000 2
    Output
    4000
    2 2

    Note

    The first example is described in the problem statement.

    In the second example there is only one possible distribution.

    In the third example the best answer is to distribute problems in the following way:[1,2000],[2000,2][1,2000],[2000,2]. The total profit of this distribution is 2000+2000=40002000+2000=4000.

    这个题就是把最大的几个数标记,平均到几天中,第一次wa了,我以为它题目里的skip是不漏掉每一项任务,后来才晓得是必须按顺序安排任务,不能跳过的!吼吼~

    我先把它按从任务从大到小排序,记录好它原本的位置,然后标记与标记之间相减,注意天数总和,最后一个就直接用天数减上一个最大任务。

    ···c++

    #include <iostream>
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<math.h>
    using namespace std;
    struct node
    {
    int num;
    int id;
    } a[2010];
    bool cmp1(node x,node y)
    {
    return x.num>y.num;
    }
    bool cmp2(node x,node y)
    {
    return x.id<y.id;
    }
    int main()
    {
    int n,k,i;
    cin>>n>>k;
    for(i=0; i<n; i++)
    {
    cin>>a[i].num;
    a[i].id=i+1;
    }
    sort(a,a+n,cmp1);
    int sum=0;
    for(i=0; i<k; i++)
    {
    sum+=a[i].num;
    }
    cout<<sum<<endl;
    sort(a,a+k,cmp2);
    if(k==1)
    {
    cout<<n<<endl;
    }
    else
    {
    for(i=0; i<k; i++)
    {
    if(i==0)
    cout<<a[i].id<<" ";
    else if(i==k-1)
    cout<<n-a[i-1].id<<endl;
    else
    cout<<a[i].id-a[i-1].id<<" ";
    }
    }
    return 0;
    }

    ···c++

     

     

    Skyscraper "MinatoHarukas"

    Mr. Port plans to start a new business renting one or more floors of the new skyscraper with one giga floors, MinatoHarukas. He wants to rent as many vertically adjacent floors as possible, because he wants to show advertisement on as many vertically adjacent windows as possible. The rent for one floor is proportional to the floor number, that is, the rent per month for the n-th floor is n times that of the first floor. Here, the ground floor is called the first floor in the American style, and basement floors are out of consideration for the renting. In order to help Mr. Port, you should write a program that computes the vertically adjacent floors satisfying his requirement and whose total rental cost per month is exactly equal to his budget.

    For example, when his budget is 15 units, with one unit being the rent of the first floor, there are four possible rent plans, 1+2+3+4+5, 4+5+6, 7+8, and 15. For all of them, the sums are equal to 15. Of course in this example the rent of maximal number of the floors is that of 1+2+3+4+5, that is, the rent from the first floor to the fifth floor.

    Input

    The input consists of multiple datasets, each in the following format.

    b 

    A dataset consists of one line, the budget of Mr. Port b as multiples of the rent of the first floor. b  is a positive integer satisfying 1 < b < 109.

    The end of the input is indicated by a line containing a zero. The number of datasets does not exceed 1000.

    Output

    For each dataset, output a single line containing two positive integers representing the plan with the maximal number of vertically adjacent floors with its rent price exactly equal to the budget of Mr. Port. The first should be the lowest floor number and the second should be the number of floors.

    Sample Input

    15
    16
    2
    3
    9699690
    223092870
    847288609
    900660121
    987698769
    999999999
    0
    

    Output for the Sample Input

    1 5
    16 1
    2 1
    1 2
    16 4389
    129 20995
    4112949 206
    15006 30011
    46887 17718
    163837 5994
    这个题看起来很复杂,我之前也想偏了,晚上被蚊子咬醒,潜意识都在构造中间数,但是这个太难实现就放弃了。
    讲道理,枚举第一项是会超时的吧,不信的话你们可以试试。
    层数小,那我就枚举层数喽
    ···c++

    #include <iostream>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    using namespace std;

    int main()
    {
    int m,n,i;
    while(cin>>m)
    {

    if(m==0)
    break;
    for(n=sqrt(2*m); n>=1; n--)
    {
    if((m-n*(n-1)/2)%n==0)
    {
    cout<<(m-n*(n-1)/2)/n<<" "<<n<<endl;
    break;
    }

    }
    }
    return 0;
    }

    ```




    The programming contest named Concours de Programmation Comtemporaine Interuniversitaire (CPCI) has a judging system similar to that of ICPC; contestants have to submit correct outputs for two different inputs to be accepted as a correct solution. Each of the submissions should include the program that generated the output. A pair of submissions is judged to be a correct solution when, in addition to the correctness of the outputs, they include an identical program.

    Many contestants, however, do not stop including a different version of their programs in their second submissions, after modifying a single string literal in their programs representing the input file name, attempting to process different input. The organizers of CPCI are exploring the possibility of showing a special error message for such close submissions, indicating contestants what's wrong with such submissions. Your task is to detect such close submissions.

    Input

    The input consists of at most 100 datasets, each in the following format.

    s

    1

    s

    2

    Each of s1 and s2 is a string written in a line, with the length between 1 and 200, inclusive. They are the first and the second submitted programs respectively. A program consists of lowercase letters (ab, ..., z), uppercase letters (AB, ...,Z), digits (01, ..., 9), double quotes ("), and semicolons (;). When double quotes occur in a program, there are always even number of them.

    The end of the input is indicated by a line containing one '.' (period).

    Output

    For each dataset, print the judge result in a line.

    If the given two programs are identical, print IDENTICAL. If two programs differ with only one corresponding string literal, print CLOSE. Otherwise, print DIFFERENT. A string literal is a possibly empty sequence of characters between an odd-numbered occurrence of a double quote and the next occurrence of a double quote.

    Sample Input

    print"hello";print123
    print"hello";print123
    read"B1input";solve;output;
    read"B2";solve;output;
    read"C1";solve;output"C1ans";
    read"C2";solve;output"C2ans";
    """"""""
    """42"""""
    slow"program"
    fast"code"
    "super"fast"program"
    "super"faster"program"
    X""
    X
    I"S""CREAM"
    I"CE""CREAM"
    11"22"11
    1"33"111
    .
    

    Output for the Sample Input

    IDENTICAL
    CLOSE
    DIFFERENT
    CLOSE
    DIFFERENT
    DIFFERENT
    DIFFERENT
    CLOSE
    DIFFERENT

    这个题真的好烦(繁)呐,分好多情况,差点把电脑砸了

    ···c++

    #include <iostream>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    using namespace std;

    int main()
    {
    string s1,s2;
    int flag;
    while(cin>>s1)
    {
    flag=0;
    if(s1[0]=='.')
    {
    break;
    }
    else
    cin>>s2;
    int len1=s1.length();
    int len2=s2.length();
    int i=0,j=0,k=0;
    while(i<len1&&j<len2)
    {
    if(s1[i]==s2[j])
    {
    if(s1[i]=='"'&&k)
    k=0;
    else if(s1[i]=='"'&&!k)
    k=1;
    i++;
    j++;
    }
    else if(k==1)
    {
    while(s1[i]!='"'&&i<len1)
    {
    i++;
    }
    while(s2[j]!='"'&&j<len2)
    {
    j++;
    }
    flag++;
    i++;
    j++;
    k=0;
    }
    else if(k==0)
    {
    flag+=2;
    break;
    }
    }
    if(k==0&&i>=len1&&j<len2)
    flag+=2;
    if(k==0&&i<len1&&j>=len2)
    flag+=2;
    if(j>=len2&&s1[i]=='"')
    flag+=2;
    else if(i>=len1&&s2[j]=='"')
    flag+=2;
    else if(i>=len1&&j<len2)
    flag++;
    else if(j>=len2&&i<len1)
    flag++;

    if(flag==0)
    cout<<"IDENTICAL"<<endl;
    else if(flag==1)
    cout<<"CLOSE"<<endl;
    else
    cout<<"DIFFERENT"<<endl;
    }
    return 0;
    }

    ```

  • 相关阅读:
    STM32F0库函数初始化系列:进入STOP模式,外部中断唤醒
    STM32F0库函数初始化系列:ADC
    STM32F0库函数初始化系列:PWM输出
    VBS病毒实验
    AWVS漏洞扫描教程之扫描方式
    利用AWVS扫描Web漏洞
    命令执行漏洞靶场练习二
    命令执行漏洞靶场练习一
    CSRF POST型
    RainbowCrack彩虹表破解密码hash
  • 原文地址:https://www.cnblogs.com/kepa/p/9368097.html
Copyright © 2020-2023  润新知