首页 > 代码库 > 练手题,没事就来AC吧 poj 4044 Score Sequence

练手题,没事就来AC吧 poj 4044 Score Sequence

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

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

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

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

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

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

不扯了,贴代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#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\n");
        else
        {
            for(i=st; i<ed; i++)
            {
                printf("%d ",str1[i]);
            }
            printf("\n");
            sort(str1+st,str1+ed,cmp2);//排序,还可以这样
            for(i=st; i<ed; i++)
            {
                printf("%d ",str1[i]);
            }
            printf("\n");
        }
    }
    return 0;
}