zoukankan      html  css  js  c++  java
  • Codeforces #333 Div.2

    Codeforces #333

    A - Two Bases

    用了pow,中招了……;

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define inf 0x3f3f3f3f3f
    int n,m;
    int c,e,x;
    int main()
    {
        scanf("%d%d",&n,&m);
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&x);
            c*=m;
            c+=x;
        }
        scanf("%d%d",&n,&m);
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&x);
            e*=m;
            e+=x;
        }
        if(c==e)
            printf("+
    ");
        else if(c>e)
            printf(">
    ");
        else
            printf("<
    ");
        return 0;
    }
    

    B-Approximating a Constant Range

    不知道为什么第一种写法不超时,第二种超时

    //ac代码
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define inf 0x3f3f3f3f3f
    int n,a[100010];
    int b;
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            for(int i=1; i<=n; i++)
                scanf("%d",&a[i]);
            int ans=2;
            int i,j;
            for(i=1; i<=n; i++)
            {
                int mm=a[i];
                int xx=a[i];
    
                for(j=i+1; j<=n; j++)
                {
                    if(a[j]>mm)
                        mm=a[j];
                    else if(a[j]<xx)
                        xx=a[j];
                    if(mm-xx>1)
                    {
                        break;
                    }
                }
                b=j-i;
                ans=max(ans,b);
                if(ans==n-i+1) break;
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
    

    //TE代码
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define inf 0x3f3f3f3f3f
    int n,a[100010];
    int b;
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            for(int i=1; i<=n; i++)
            {
                scanf("%d",&a[i]);
            }
            int ans=0;
            int i,j;
            for(i=1; i<=n; i++)
            {
                int mm=a[i];
                int xx=a[i];
                for(j=i+1; j<=n; j++)
                {
                    if(abs(mm-a[j])<=1 && abs(xx-a[j])<=1)
                    {
                        mm=min(mm,a[j]);
                        xx=max(xx,a[j]);
                    }
                    else
                        break;
                }
                b=j-i;
                ans=max(ans,b);
                if(ans==n-i+1) break;
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    二层设备与三层设备的区别--总结
    转载-vim配置收藏
    Docker入门
    Docker入门
    Docker入门
    Docker入门
    Docker入门
    树莓派进阶之路 (037)
    基于Centos搭建个人 Leanote 云笔记本
    基于CentOS搭建私有云服务
  • 原文地址:https://www.cnblogs.com/zzulipomelo/p/4993517.html
Copyright © 2011-2022 走看看