zoukankan      html  css  js  c++  java
  • 7.30测试

    第一题 蛇形数字三角形

    考试的时候因为智障%5d后面还加了个空格然后就爆0了....

    #include<iostream>
    #include<cstdio>
    using namespace std;
    #define tcl(a,b,c) for(a=b;a<=c;a++)
    const int maxx=35;
    int a[maxx][maxx];
    int main()
    {
        int n,i,j;
        cin>>n;
        int sum=n*(n+1)/2,q=1;
        a[1][1]=1;
        int m=n+1;
        int t=2;
        tcl(j,2,n)
        {
            a[j][1]=a[j-1][1]+t;
            t++;
            //cout<<a[j][1];
        }
        tcl(j,1,n)
        {
            int tt=q;
            printf("%5d",a[j][1]);
            tcl(i,2,m-1)
            {
                a[j][i]=a[j][i-1]+q;
                q++;
                printf("%5d",a[j][i]);
            }
            cout<<endl;
            m--,q=tt+1;
        }
        return 0;
    }
    

    但是如果自己不智障这个题不难。关键是不可能不智障

    第二题 点的移动

    其实就是枚举什么的

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    int x[55],y[55],d[55],ans[55];
    int i,j,k,n;
    int main()
    {
        cin>>n;
        for(i=1;i<=n;i++)
        {
            cin>>x[i]>>y[i];
        }
        for(k=1;k<=n;k++)
        {
            ans[k]=999999999;
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                for(k=1;k<=n;k++)
                {
                    d[k]=abs(x[k]-x[i])+abs(y[k]-y[j]);//枚举
                }
                sort(d+1,d+n+1);//排序
                int s=0;
                for(k=1;k<=n;k++)
                {
                    s=s+d[k];
                    if(s<ans[k])
                    {
                        ans[k]=s;
                    }
                }
            }
        }
        for(k=1;k<=n;k++)
        {
            cout<<ans[k]<<endl;
        }
        return 0;
    }
    

    也不是很难。

    第三题 最美字串

    #include<iostream>
    using namespace std;
    int main()
    {
        long long counto,countx,maxo,maxx;
        while (cin>>counto>>countx>>maxo>>maxx)
        {
            maxo=min(counto,maxo);
            maxx=min(countx,maxx);
            if (maxo==0) cout<<maxx<<endl;
            else if (maxx==0) cout<<maxo<<endl;//特判
            else if ((counto+1)*maxx<countx) cout<<(counto+1)*maxx+counto<<endl;
            else if ((countx+1)*maxo<counto) cout<<(countx+1)*maxo+countx<<endl;
            else cout<<counto+countx<<endl;//如果没有任何天赋就直接死加上去好了。
        }
        return 0;
    }
    

    第四题 牢房

    #include<iostream> 
    #include<cstdio> 
    #include<algorithm>
    using namespace std;  
    int s[110][110]={0},p,q,a[110]={0},sum[110]={0};  
    inline void init()  
    {  
        scanf("%d%d",&p,&q);  
        for(int i=1;i<=q;i++)scanf("%d",&a[i]);  
        a[0]=0;a[++q]=p+1;  
        sort(a,a+q+1);  
        return;  
    }  
    
    int main()  
    {  
        init();  
        for(int i=1;i<=q;i++)  
        	sum[i]=a[i]-a[i-1]-1+sum[i-1]; 
        for(int k=2;k<=q;k++)  
        for(int i=1;i<=q-k+1;i++)  
        {  
            int j=i+k-1;  
            for(int p=i;p<j;p++)  
            if(!s[i][j]||s[i][j]>s[i][p]+s[p+1][j]+sum[j]-sum[i-1]+j-i-1)
            s[i][j]=s[i][p]+s[p+1][j]+sum[j]-sum[i-1]+j-i-1;  
        }  
        printf("%d",s[1][q]);  
        return 0;  
    }  
    
  • 相关阅读:
    微服务架构技术栈选型手册(万字长文)
    Visual Studio 2013 always switches source control plugin to Git and disconnect TFS
    Visual Studio 2013 always switches source control plugin to Git and disconnect TFS
    MFC对话框中使用CHtmlEditCtrl
    ATL开发 ActiveX控件的 inf文件模板
    ActiveX: 如何用.inf和.ocx文件生成cab文件
    Xslt 1.0中使用Array
    如何分隔两个base64字符串?
    An attempt was made to load a program with an incorrect format
    JQuery 公网 CDN
  • 原文地址:https://www.cnblogs.com/LSWorld/p/730test.html
Copyright © 2011-2022 走看看