• hdu6570Wave (暴力求解)


    Problem Description
    Avin is studying series. A series is called "wave" if the following conditions are satisfied:
    1) It contains at least two elements;
    2) All elements at odd positions are the same;
    3) All elements at even positions are the same;
    4) Elements at odd positions are NOT the same as the elements at even positions.
    You are given a series with length n. Avin asks you to find the longest "wave" subseries. A subseries is a subsequence of a series.
     
    Input
    The first line contains two numbers n, c (1 ≤ n ≤ 100, 000, 1 ≤ c ≤ 100). The second line contains n integers whose range is [1, c], which represents the series. It is guaranteed that there is always a "wave" subseries.
     
    Output
    Print the length of the longest "wave" subseries.
     
    Sample Input
    5 3 1 2 1 3 2
     
    Sample Output
    4
     
    Source
     
    中文题意:给你两个数n,c;接下来会再给你n个数在[1,c]之间;
    问你从其中找出一个子序列,使得奇数的位置所有的数都相等,所有偶数的位置也相等,但奇数与偶数位置的数不能相等;
    这个奇数位置,偶数位置是相对于你选出来的子序列,在子序列中的位置
     
    思路:暴力求解:记下n个数中重复出现数的个数,然后每两个组合,查找这两个数可以组成的最长子序列;
     
    AC624ms:

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int num[100005];
    struct node{
    int number,quanlity;//第一个存储表示的是哪一个数,第二个表示这个数的个数
    }d[105];
    int cmp(struct node x,struct node y){
    return x.quanlity>y.quanlity;
    }
    int main(){
    int n,c;
    scanf("%d%d",&n,&c);
    for(int i=0;i<=100;i++)
    d[i].quanlity=0,d[i].number=i;
    for(int i=0;i<n;i++)
    scanf("%d",&num[i]),d[num[i]].quanlity++;
    /* for(int i=0;i<c;i++)
    printf("%d %d ",d[i].number,d[i].quanlity);*/
    int maxn=0;
    for(int i=0;i<c-1;i++){
    for(int ii = i+1;ii<c;ii++){
    int s = 1 , x = d[i].number , y = d[ii].number , mm , j;
    for(j=0;j<n;j++){if(num[j]==x||num[j]==y) {mm=num[j];break;}}
    for(;j<n;j++){
    if(num[j]==x||num[j]==y){
    if(num[j]!=mm) s++,mm=num[j];
    }
    }
    if(s>maxn) maxn=s;
    }
    }
    printf("%d ",maxn);
    return 0;
    }

    //10 4
    //1 4 3 1 3 1 2 2 1 2


    作者:孙建钊
    出处:http://www.cnblogs.com/sunjianzhao/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    linux之awk命令
    HDU 2097 Sky数 进制转换
    HDU 2077 汉诺塔IV
    HDU 2094 产生冠军 dfs加map容器
    HDU 2073 叠框
    HDU 2083 简易版之最短距离
    HDU 2063 过山车 二分匹配
    天梯 1014 装箱问题
    天梯 1214 线段覆盖
    天梯 1098 均分纸牌
  • 原文地址:https://www.cnblogs.com/sunjianzhao/p/11674523.html
Copyright © 2020-2023  润新知