zoukankan      html  css  js  c++  java
  • 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/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    0129 System类 Math类 Arrays类 大数据运算
    0127 基本类型包装类
    'telnet' 不是内部或外部命令,也不是可运行的程序 解决方案
    删除时报org.springframework.dao.DataIntegrityViolationException
    mapper自动识别驼峰配置 spring MVC
    spring Security如何debug源码
    公司tomcat项目启动
    java.util.ConcurrentModificationException: null 异常解决
    @Transactional 学习
    mangoDB初探
  • 原文地址:https://www.cnblogs.com/sunjianzhao/p/11674523.html
Copyright © 2011-2022 走看看