• Codeforces Round #332 (Div. 2)


    好菜,不说话了,说题。

    A - Patrick and Shopping

    从一个点出发,要经过其他两个点,然后回到原地,求最小时间花费。只有四种情况,从中选一个最小的就行了。

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    #include <math.h>
    #include <algorithm>
    using namespace std;
    
    int main(int argc, const char * argv[]) {
        // insert code here...
        int a,b,c;
        cin>>a>>b>>c;
        int ans=a+b+c;
        ans=min(2*a+2*b,ans);
        ans=min(2*a+2*c,ans);
        ans=min(2*b+2*c,ans);
        cout<<ans<<endl;
        return 0;
    }

    B - Spongebob and Joke

    这题,思路还是很简单,唯一要注意的是,当有多种情况和不可能同时发生时,输出不可能。 这里被HACK了。。。 

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    #include <math.h>
    #include <algorithm>
    using namespace std;
    
    int f[100100],d[100100];
    int mark[100100];
    int mylink[100100];
    
    int main(int argc, const char * argv[]) {
        // insert code here...
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",f+i);
            mark[ f[i] ]++;
            mylink[ f[i] ] = i;
        }
        for(int i=1;i<=m;i++)
            scanf("%d",d+i);
        int flag=0;
        int mul=0;
        for(int i=1;i<=m;i++)
        {
            if( mark[ d[i] ] == 0 )
            {
                flag=-1;
                break;
            }
            if( mark[ d[i] ]>1)
            {
                mul=1;
            }
        }
        if(flag==-1) printf("Impossible");
        else
            if(mul==1) printf("Ambiguity
    ");
        else
        {
            printf("Possible
    ");
            for(int i=1;i<=m;i++)
                printf("%d ",mylink[ d[i] ]);
        }
        return 0;
    }

    C - Day at the Beach

    把一个长为N序列,分成n块,使得对于0<=i<n,max(i)<min(i+1)

    这样只需要记录从1->i的最大值max(i),和从i->n的最小值min(i)即可。

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    #include <math.h>
    #include <algorithm>
    using namespace std;
    
    int g[100100];
    int mx[100100],mi[100100];
    
    int main(int argc, const char * argv[]) {
        // insert code here...
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
            scanf("%d",g+i);
        mx[1]=g[1];
        for(int i=2;i<=n;i++)
        {
            mx[i]=max(mx[i-1],g[i]);
        }
        mi[n]=g[n];
        for(int i=n-1;i>=0;i--)
        {
            mi[i]=min(mi[i+1],g[i]);
        }
        int ans=0;
        for(int i=1;i<n;i++)
        {
            if( mx[i] <= mi[i+1] ) ans++;
        }
        cout<<ans+1<<endl;
        return 0;
    }

    D - Spongebob and Squares

    看到这题,我真是TM的菜,1个半小时没做出来,其实10分钟就已经想到思路了。先写了程序验证是否可行,然后在推公式的时候又碰到一些问题。

    后面想想,如果不会推公式的话用二分暴力完全是可以的。

    问题可以变成,给出一个n

    从1-n开始枚举。

    1:  x=n

    2:  3x-1=n

    3:  6x-4=n

    4:  10x-10

    5:  15x-20

    6:  21x-35

       ...

    n:  (n*(n+1)/2)*x - n*(n+1)*(n-1)/6

    然后判断x是否是整数,然后如果枚举过程中,如果x大于i,则结束。稍微分析可以知道(x绝对是小于10^6)

    //
    //  main.cpp
    //  cf332
    //
    //  Created by 陈加寿 on 15/11/21.
    //  Copyright (c) 2015年 陈加寿. All rights reserved.
    //
    
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    #include <math.h>
    #include <algorithm>
    using namespace std;
    
    long long aa[10001000],bb[10001000];
    
    int main(int argc, const char * argv[]) {
        // insert code here...
            unsigned long long n;
        cin>>n;
        if(n==1)
        {
            printf("1
    1 1
    ");
            return 0;
        }
        int ans=0;
        ans=1;
        aa[0]=1;bb[0]=n;
        int flag=0;
        for(unsigned long long i=2;i<=n;i++)
        {
            unsigned long long tmp1,tmp2,tmp3;
            tmp1 = i*(i-1)/2*(i+1)/3;//这个语句还是有问题的感觉。
            tmp2 = i*(i+1)/2;
            
            tmp3= (n+tmp1)/tmp2;
            
            if( (n+tmp1)%tmp2==0 )
            {
                if(tmp3 <= i)
                {
                    if(i == tmp3)
                    {
                        aa[ans] = tmp3;
                        bb[ans] = tmp3;
                        flag=1;
                        ans++;
                    }
                    break;
                }
                aa[ans]=i; bb[ans]=tmp3; ans++;
            }
            if(tmp3<i) break;
        }
        for(int i=ans-flag-1;i>=0;i--)
        {
            aa[ ans ]=bb[i];
            bb[ ans ]=aa[i];
            ans++;
        }
        cout<<ans<<endl;
        for(int i=0;i<ans;i++)
        {
            cout<<aa[i]<<" "<<bb[i]<<endl;
        }
        return 0;
    }
  • 相关阅读:
    How to make BBED(Oracle Block Brower and EDitor Tool) on Unix/Linux/Windows
    直接路径读取对于延迟块清除的影响
    Mysql:日志管理:一般查询日志、慢速查询日志的
    Mysql:函数之二: miscellaneous functions
    Mysql:函数之三: date and time functions:重要的格式化函数
    Mysql:日志管理:综述
    Mysql:函数之三: date and time functions
    程序员阿BEN的SOHO生活
    网页常用Javascript
    优秀程序员的十个习惯
  • 原文地址:https://www.cnblogs.com/chenhuan001/p/4984092.html
Copyright © 2020-2023  润新知