zoukankan      html  css  js  c++  java
  • CodeForces#378--A, B , D--暴力出奇迹....

    A题

    A. Grasshopper And the String
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.

    Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.

    The picture corresponds to the first example.

    The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.

    Input

    The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.

    Output

    Print single integer a — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.

    Examples
    Input
    ABABBBACFEYUKOTT
    Output
    4
    Input
    AAA
    Output
    1

     遇到从一个元音字母跳向另一个元音字母, 求最大的跳跃间隔. 特别注意全是辅音字母的情况. 暴力水题...

    #include<bits/stdc++.h>
    using namespace std;
    char a[6]={'A','E','I','O','U','Y'};
    bool ok(char c)
    {
        for(int i=0;i<6;i++){
            if(c==a[i])
                return 1;
        }
        return 0;
    }
    int main()
    {
        //freopen("data.in","r",stdin);
        string str;
        int flag=0;
        int res=-1;
        while(cin>>str){
            res=-1;
            flag=0;
            for(int i=0;i<str.length();i++){
                flag++;
                if(ok(str[i])){
    //                cout<<11111111<<endl;
                    res=max(flag,res);
                    flag=0;
                }
            }
            res=max(flag+1,res);
            cout<<res<<endl;
            str.clear();
        }
    }

    B题

    B. Parade
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.

    There will be n columns participating in the parade, the i-th column consists of li soldiers, who start to march from left leg, and ri soldiers, who start to march from right leg.

    The beauty of the parade is calculated by the following formula: if L is the total number of soldiers on the parade who start to march from the left leg, and R is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal |L - R|.

    No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index i and swap values li and ri.

    Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty.

    Input

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

    The next n lines contain the pairs of integers li and ri (1 ≤ li, ri ≤ 500) — the number of soldiers in the i-th column which start to march from the left or the right leg respectively.

    Output

    Print single integer k — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.

    Consider that columns are numbered from 1 to n in the order they are given in the input data.

    If there are several answers, print any of them.

    Examples
    Input
    3
    5 6
    8 9
    10 3
    Output
    3
    Input
    2
    6 5
    5 6
    Output
    1
    Input
    6
    5 9
    1 3
    4 8
    4 5
    23 54
    12 32
    Output
    0
    Note

    In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.

    If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal 5 + 8 + 3 = 16, and who march from the right leg — 6 + 9 + 10 = 25. In this case the beauty equals |16 - 25| = 9.

    It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9.

     目标是使左边的和与右边的和差值最大, 可以交换不多于一行的左值与右值. 一开始我还想去找规律, 没想到暴力处理竟然不超时就过了...汗....

    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN=100010;
    int l[MAXN];
    int r[MAXN];
    int suml,sumr;
    int main()
    {
        //freopen("data.in","r",stdin);
        int n;
        int flag;
        int cc;
        while(cin>>n){
            suml=sumr=0;
            for(int i=1;i<=n;i++){
                cin>>l[i]>>r[i];
                suml+=l[i];
                sumr+=r[i];
            }
            int res=abs(suml-sumr);
            flag=0;
            int ll=suml;
            int rr=sumr;
            for(int i=1;i<=n;i++){
                cc=abs(l[i]-r[i]);
                if(l[i]<r[i]){
                    ll+=cc;
                    rr-=cc;
                }
                else{
                    ll-=cc;
                    rr+=cc;
                }
                if(res<abs(ll-rr)){
                    res=abs(ll-rr);
                    flag=i;
                }
                ll=suml;
                rr=sumr;
            }
            cout<<flag<<endl;
        }
    }

    D题

    D. Kostya the Sculptor
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere.

    Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya.

    If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way.

    Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar.

    Input

    The first line contains the integer n (1 ≤ n ≤ 105).

    n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.

    Output

    In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data.

    You can print the stones in arbitrary order. If there are several answers print any of them.

    Examples
    Input
    6
    5 5 5
    3 2 4
    1 4 1
    2 1 3
    3 2 4
    3 3 4
    Output
    1
    1
    Input
    7
    10 7 8
    5 10 3
    4 2 6
    5 5 5
    10 2 8
    4 2 1
    7 7 7
    Output
    2
    1 5
    Note

    In the first example we can connect the pairs of stones:

    • 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1
    • 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively.
    • 2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5
    • 4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1
    • 5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5

    Or take only one stone:

    • 1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5
    • 2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1
    • 3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5
    • 4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5
    • 5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1
    • 6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5

    It is most profitable to take only the first stone.

     给出n块方块, 拿出1块或2块, 使其组合之后内切圆最大(最小的边最大),我的处理方法是将每块方块处理为3块,记录一下每个方块原本的序号, 然后排序, 从而可以和当前位置匹配的方块一定在当前位置附近, 暴力枚举即可.

    然后今天早上看到了一个特别巧妙的处理方法, 不用将1块处理为3块:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    struct node{
        int a,b,c,lab;
    }e[100005];
    bool cmp(node a,node b){
        if(a.c==b.c&&a.b==b.b)return a.a<b.a;
        if(a.c==b.c)return a.b<b.b;
        return a.c<b.c;
    }
    bool pick(int a,int b){
        if(e[a].c==e[b].c&&e[a].b==e[b].b) return 1;
        return 0;
    }
    int main(){
        int n,i,j,x,y,z,ans=0,k=1,t,ans1,ans2,dd;
        scanf("%d",&n);
        for(i=1;i<=n;i++){
            scanf("%d%d%d",&x,&y,&z);
            int s1=min(x,min(y,z)),s2=max(x,max(y,z));
            if(s1>ans){
                ans=s1;
                dd=i;
                t=1;
            }
            e[i].a=s1;
            e[i].b=x+y+z-s1-s2;
            e[i].c=s2;
            e[i].lab=i;
        }
        sort(e+1,e+1+n,cmp);
        for(i=n;i>=2;i--){
            if(pick(i-1,i)){
                int ss=min(e[i].a+e[i-1].a,min(e[i].b,e[i].c));
                if(ss>ans){
                    t=2;
                    ans=ss;
                    ans2=e[i].lab;
                    ans1=e[i-1].lab;
                }
            }
        }
        printf("%d
    ",t);
        if(t==1)printf("%d
    ",dd);
        else printf("%d %d
    ",ans1,ans2);
        return 0;
    }
  • 相关阅读:
    shutil文件去重模块
    Nexus构建npm、yum、maven私有仓库
    centos7添加自定义服务到systemctl
    Sonatype nuxus私有仓库介绍
    rancher单节点备份和恢复
    rancher证书过期X509:certificate has expired or is not ye valid
    清理docker日志
    mysql 9 hash索引和B+tree索引的区别
    mysql 8 索引
    mysql 7 慢查询+慢查询工具
  • 原文地址:https://www.cnblogs.com/liuzhanshan/p/6018863.html
Copyright © 2011-2022 走看看