zoukankan      html  css  js  c++  java
  • 练手题,没事就来AC吧 poj 4044 Score Sequence

    此题为12年金华邀请赛A题

    克隆了下比赛,A题最简单,也是最挑战人数据处理能力的一题,可惜自己数据处理能力太弱

    久久不能写出代码…………

    总结下就是题做少了,平时应多做题,少灌水,应放下看电影的时间,玩各种软件的时间

    先做好一项再说才是正道,看到一句话说得好

    “   人有两条路要走,一条是必须走的,一条是想走的,你必须把必须走的路走漂亮,才可以走想走的路...

    不扯了,贴代码:

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <algorithm>
    #include <iostream>
    
    using namespace std;
    
    int str1[105],str2[105];
    bool cmp1(int x,int y)
    {
        return x>y;
    }
    int cmp2(int x,int y)
    {
        if(x%10==y%10)return x<y;
        return x%10 < y%10;
    }
    
    int main()
    {
        int n,m,k,t;
        int i,j;
        scanf("%d",&t);
        while(t--)
        {
            memset(str1,-1,sizeof(str1));
            memset(str2,-1,sizeof(str2));
            scanf("%d%d",&n,&m);
            for(i=0; i<n; i++)
            {
                scanf("%d",&str1[i]);
                for(j=0; j<i; j++)
                {
                    if(str1[i]==str1[j])//去重合
                    {
                        i--;
                        n--;
                    }
                }
            }
            for(i=0; i<m; i++)
            {
                scanf("%d",&str2[i]);
                for(j=0; j<i; j++)
                {
                    if(str2[i]==str2[j])
                    {
                        m--;
                        i--;
                    }
                }
            }
            sort(str1,str1+n,cmp1);
            sort(str2,str2+m,cmp1);//for(i=0;i<n;i++)printf("%d^^",str1[i]);
            int maxn=0,st=0,ed=0;
            for(i=0; i<n; i++)
            {
                for(j=0; j<m; j++)
                {
                    if(str1[i]==str2[j])
                    {
                        int k=0;
                        while(i+k<n&&j+k<m&&(str1[i+k]==str2[j+k]))
                        {
                            k++;//暴力
                        }
                        //printf("%dfuck^^",k);
                        if(k>maxn)
                        {
                            st=i;
                            ed=i+k;
                            maxn=k;
                        }
                    }
                }
            }
            if(maxn==0)printf("NONE
    ");
            else
            {
                for(i=st; i<ed; i++)
                {
                    printf("%d ",str1[i]);
                }
                printf("
    ");
                sort(str1+st,str1+ed,cmp2);//排序,还可以这样
                for(i=st; i<ed; i++)
                {
                    printf("%d ",str1[i]);
                }
                printf("
    ");
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    hdu 5007 水题 (2014西安网赛A题)
    hdu 1698 线段树(成段替换 区间求和)
    poj 3468 线段树 成段增减 区间求和
    hdu 2795 公告板 (单点最值)
    UVaLive 6833 Miscalculation (表达式计算)
    UVaLive 6832 Bit String Reordering (模拟)
    CodeForces 124C Prime Permutation (数论+贪心)
    SPOJ BALNUM (数位DP)
    CodeForces 628D Magic Numbers (数位DP)
    POJ 3252 Round Numbers (数位DP)
  • 原文地址:https://www.cnblogs.com/ccccnzb/p/3721040.html
Copyright © 2011-2022 走看看