• 太阳好大我好怕


    在连续两晚上热哭了之后,好不容易呼吁寝室交了空调租赁费,修空调的人修好之后拔腿就跑,发现空调是烂的,现在让他来修结果他还紧都拖。

    这两天天天往106跑,不是说他们寝室氛围有多浓厚,就是单纯的想蹭个空调,都要蹭到不好意思了。

    不说了先看题。

    这个题我当时一直想用队列做,然后失败了,愤懑的我就洗头去了。

    其实就是substr的用法,掌握了差不多就能搞出来,以后不许自己这么菜。

    A. Many Equal Substrings
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given a string tt consisting of nn lowercase Latin letters and an integer number kk.

    Let's define a substring of some string ss with indices from ll to rr as s[lr]s[l…r].

    Your task is to construct such string ss of minimum possible length that there are exactly kk positions ii such that s[ii+n1]=ts[i…i+n−1]=t. In other words, your task is to construct such string ss of minimum possible length that there are exactly kk substrings of ss equal to tt.

    It is guaranteed that the answer is always unique.

    Input

    The first line of the input contains two integers nn and kk (1n,k501≤n,k≤50) — the length of the string tt and the number of substrings.

    The second line of the input contains the string tt consisting of exactly nn lowercase Latin letters.

    Output

    Print such string ss of minimum possible length that there are exactly kk substrings of ss equal to tt.

    It is guaranteed that the answer is always unique.

    Examples
    input
    Copy
    3 4
    aba
    output
    Copy
    ababababa
    input
    Copy
    3 2
    cat
    output
    Copy
    catcat
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<string>
    #include<vector>
    
    using namespace std;
    
    int main()
    {
        int n, m,i,temp;
        string s;
        cin >> n >> m >> s;
        for(i=0;i<n;i++)
        {
            if(s.substr(0,i)==s.substr(n-i,i))
            {
                temp=i;
            }
        }
        for(i=1;i<m;i++)
            cout<<s.substr(0,n-temp);
        cout<<s<<endl;
        return 0;
    }

     这个题就是贪心。找到最大次大的左端点和最小次小的右端点比较即可。

    C. Maximal Intersection
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given nn segments on a number line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.

    The intersection of a sequence of segments is such a maximal set of points (not necesserily having integer coordinates) that each point lies within every segment from the sequence. If the resulting set isn't empty, then it always forms some continuous segment. The length of the intersection is the length of the resulting segment or 00 in case the intersection is an empty set.

    For example, the intersection of segments [1;5][1;5] and [3;10][3;10] is [3;5][3;5] (length 22), the intersection of segments [1;5][1;5] and [5;7][5;7] is [5;5][5;5](length 00) and the intersection of segments [1;5][1;5] and [6;6][6;6] is an empty set (length 00).

    Your task is to remove exactly one segment from the given sequence in such a way that the intersection of the remaining (n1)(n−1)segments has the maximal possible length.

    Input

    The first line contains a single integer nn (2n31052≤n≤3⋅105) — the number of segments in the sequence.

    Each of the next nn lines contains two integers lili and riri (0liri1090≤li≤ri≤109) — the description of the ii-th segment.

    Output

    Print a single integer — the maximal possible length of the intersection of (n1)(n−1) remaining segments after you remove exactly one segment from the sequence.

    Examples
    input
    Copy
    4
    1 3
    2 6
    0 4
    3 3
    output
    Copy
    1
    input
    Copy
    5
    2 6
    1 3
    0 4
    1 20
    0 4
    output
    Copy
    2
    input
    Copy
    3
    4 5
    1 2
    9 20
    output
    Copy
    0
    input
    Copy
    2
    3 10
    1 5
    output
    Copy
    7

    By authentic, contest: Codeforces Round #506 (Div. 3), problem: (C) Maximal Intersection, Accepted, #
     #include <iostream>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    struct node
    {
        int x;
        int y;
    }a[300001];
    bool cmp(int x,int y)
    {
        return x>y;
    }
    int x[300001],y[300001];
    int main()
    {
     int n,i;
     cin>>n;
     for(i=0;i<n;i++)
     {
        cin>>a[i].x>>a[i].y;
       x[i]=a[i].x;
       y[i]=a[i].y;
    }
    sort(x,x+n,cmp);
    sort(y,y+n);
    int l1=x[0],l2=x[1];
    int r1=y[0],r2=y[1];
    for(i=0;i<n;i++)
    {
        if(a[i].x==l1&&a[i].y==r1)
        {
            cout<<r2-l2<<endl;
            return 0;
        }
    }
    cout<<max(0,max(r1-l2,r2-l1))<<endl;
    return 0;
    }

    这道题就有点巧妙了,他让你算中间间隔为n的倍数的为1的位置,那么我们就对n取余,余数相同者满足条件

    There is a long fence not far from H &H office. A while ago boards of the fence were painted in different colors. Now H &H CTO wants to know, if there are two red boards in the fence with the number of boards between them multiple to K.

    Input

    The first line contains the integer number K (1 ≤ K ≤ 100000). The second line contains the description of the fence. Symbol ——"1" indicates the red board, and symbol "0" —— any other. The fence contains not more than 100000 boards.

    Output

    Output the numbers of required boards, or output two zeros if they do not exist. Boards are numbered starting with 1 from left to right.

    Sample Input

    3
    00101000010

    Sample Output

    3 10
    #include <iostream>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    int a[100010];
    int main()
    {
     int n,i,j;
     char s[100010];
     cin>>n;
     scanf("%s",s+1);
     int len=strlen(s+1);
     for(i=1;i<=len;i++)
     {
         if(s[i]=='1')
         {
             if(a[(i-1)%n])
             {
                cout<<a[(i-1)%n]<<" "<<i<<endl;
             return 0;
             }
               a[i%n]=i;
         }
     }
     cout<<0<<" "<<0<<endl;
     return 0;
    }

    修空调的人快来!不然我就画个圈圈诅咒你。。。

  • 相关阅读:
    快速提取某一文件夹下所有文件名称
    CFileFind类的使用总结
    FILE文件流的中fopen、fread、fseek、fclose的使用
    经典损失函数:交叉熵(附tensorflow)
    tensorboard使用
    Windows下 tensorboard出现ValueError:Invalid format string
    新建全色或者resize(毫无价值,只是做记录)
    创建一个任意大小的全色矩阵 python
    转移图片位置
    getpatch
  • 原文地址:https://www.cnblogs.com/kepa/p/9554470.html
Copyright © 2020-2023  润新知