• codeforce A. 2Char(水题,暴力)


    今晚发了个蛇精病,然后CF了,第一题这好难啊,然而水题一个,暴力飘过。

    链接http://codeforces.com/contest/593/problem/A;

    题意比较难懂吗?傻逼百度都翻译不对,更别说我这22了,但后来还是看懂了,没办法,就这么任性。

    题意是给你N个串,然后让你选这选串中的几个要求是最后有这几个串组成的串就只有最多两个不同的字符构成,并且要最长。

    那么开始分析,因为就26个因为字母爆力求一下枚举不同组合就行了,然后再从所给的字串中找符合要求的字串,用maxx记录最大值,开始maxx赋值为0;

    然后每次更新maxx就行了(水题吧)。复杂度为26*26*n*l(l为最长串的长度)复杂最高不超过5*1e7;

    下面看代码:

     1 #include<stdio.h>
     2 #include<algorithm>
     3 #include<stdlib.h>
     4 #include<string.h>
     5 using namespace std;
     6 int a[26];
     7 typedef struct pp
     8 {
     9    char bb[1005];
    10 
    11 } ss;
    12 ss kk[102];
    13 int main(void)
    14 {
    15     int n,i,j,k,p,q,l;
    16     int b[26];
    17     while(scanf("%d",&n)!=EOF)
    18     {
    19         for(i=0; i<n; i++)
    20         {
    21             scanf("%s",kk[i].bb);
    22         }
    23         int maxx=0;
    24         for(i=0; i<26; i++)
    25         {
    26             for(j=i; j<26; j++)
    27             {//暴力枚举
    28                 int vv=0;
    29                 for(k=0; k<n; k++)
    30                 {
    31                     int zz=0;
    32                     l=strlen(kk[k].bb);
    33                     for(p=0; p<l; p++)
    34                     {
    35                         if(kk[k].bb[p]-'a'==i||kk[k].bb[p]-'a'==j)
    36                         {
    37                             zz++;
    38                         }
    39                         else
    40                         {
    41                             break;//如果出现其他字母直接跳出
    42                         }
    43                     }
    44                     if(p==l)//表明字串符合要求就加上字串的长度
    45                     {
    46                         vv+=l;
    47                     }
    48                 }
    49                 if(vv>maxx)
    50                 {
    51                     maxx=vv;
    52                 }
    53             }
    54         }
    55         printf("%d
    ",maxx);
    56     }
    57     return 0;
    58 }
    油!油!you@
  • 相关阅读:
    mysql check约束无效
    Illegal mix of collations for operation 'concat'
    执行automake时报错 error while making link: Operation not supported
    GCC 编译详解[转]
    gcc的选项
    关于MFLAGS与MAKEFLAGS
    gcc和g++的区别
    g++参数介绍
    gcc/g++基本命令简介
    semver语义化版本号
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/4937980.html
Copyright © 2020-2023  润新知