2486: Stock Wave

本文介绍了一种算法,用于从一系列历史价格数据中找出最长的波动序列(即“波浪”),这是一种先升后降再重复的模式。输入是一系列正数价格,输出是最长波动序列的长度。

2486: Stock Wave


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s32768K1208188Standard

As a stock analyst, Tom can forecast the trend according to a series of historical prices. To find the "Wave" is the first thing that he needs to do.

A "Wave" is a series of prices, the value in even place is greater than the former one, and the value in odd place is less than the former one. If you draw these values in one curve, you will see "up, down, up, down ...." Yes, it is a "Wave".

Can you help Tom to find out the longest "Wave"?

Input

The first line of each case is a positive integer n (n < 1000). The next n line(s) is a price with two decimal places.

Output

Print the length of the longest "Wave" in the input, if the length is less than 3, output '0'.

Sample Input

5
1.00
8.10
3.00
5.00
4.00 
4
1.01
2.02
3.03
4.04

Sample Output

5
0

Hint

The longest "Wave" is a subsequence of initial price series, the neighboring values of "Wave" may be NOT neighboring in the original series, but they must keep order of input.

 

Problem Source: provided by skywind

#include<iostream>
using namespace std;
const  int maxn=1000;
int main()
{
 int n;
 double a[maxn+1];
 while(cin>>n)
 {
  int i,j;
   for(i=0;i<n;i++)
   cin>>a[i];
  int sum[maxn+1];//表示前n个数的最大波长
  int lab[maxn+1];//标记状态 0表示位于波峰  1表示位于波谷
  lab[0]=sum[0]=1;
  int t=-1;
  for(int k=1;k<n;k++)
  {
   if(a[k]>a[k-1])
   {
    t=k;
    break;
   }
  }
  if(t==-1) {cout<<"0"<<endl;continue;}
  for(i=0;i<t;i++)
   sum[i]=lab[i]=1;
  for(i=t;i<n;i++)
  {
   int max=0;
   int f=2;
   for(j=i-1;j>=0;j--)
   {
    if(lab[j]==0&&a[i]<a[j])//表示可形成波谷
    {
     if(sum[j]>max)
     {
      max=sum[j];
      f=1;//及当前状态为波峰
     }
    }
    else if(lab[j]==1&&a[i]>a[j]) //表示可形成波峰
    {
     if(sum[j]>max)
     {
      max=sum[j];
      f=0;//记当前状态为波谷
     }
    }
    
   }
  
   sum[i]=max+1;
    lab[i]=f;
   
  }
  if(sum[n-1]<3) sum[n-1]=0;
  cout<<sum[n-1]<<endl;
 }
 return 0;
}

 

 

//底部导航 "tabBar":{ "borderStyle":"white", "backgroundColor":"#fafafc", "selectedColor":"#55aaff", "color":"#000000", "list":[ { "iconPath":"/static/images/index/index.png", "selectedIconPath":"/static/images/index/index-fill.png", "text":"首页", "pagePath":"pages/tabbar/index/index" }, { "iconPath":"/static/images/index/user.png", "selectedIconPath":"/static/images/index/user-fill.png", "text":"个人信息", "pagePath":"pages/tabbar/userInfo/userInfo" } ] }将全局样式转变成局部样式 <template> <!-- 完全移除搜索区域后的页面结构 --> <view class="warehouse-container"> <!-- 顶部导航栏保持不变 --> <view class="header"> <!-- 用户信息等保持不变 --> </view> <!-- 欢迎横幅保持不变 --> <view class="welcome-banner"> <view class="banner-content"> <view class="welcome-title"> <text class="welcome-text">欢迎使用</text> <text class="system-name">智慧仓储管理系统</text> </view> <text class="welcome-subtitle">高效 · 精准 · 智能化管理您的仓库</text> </view> <image src="/static/wave.png" class="banner-wave" /> </view> <!-- 核心功能区 --> <view class="main-functions"> <!-- 功能网格 --> <view class="function-grid"> <view v-for="(item, index) in functions" :key="index" class="grid-item" @tap="navigateTo(item.path)" > <view class="icon-wrapper"> <uni-icons :type="item.icon" size="50" color="#5e8fff"></uni-icons> </view> <text class="item-label">{{ item.label }}</text> </view> </view> <!-- 库存概览 --> <!-- <view class="inventory-section"> <view class="section-header"> <text class="section-title">库存概览</text> <text class="view-all" @tap="navToInventory">查看全部 ></text> </view> <view class="inventory-metrics"> <view class="metric-card"> <text class="metric-value">1,256</text> <text class="metric-label">库存种类</text> </view> <view class="metric-card warning"> <text class="metric-value">48</text> <text class="metric-label">库存预警</text> </view> <view class="metric-card"> <text class="metric-value">¥256,890</text> <text class="metric-label">库存总值</text> </view> </view> </view> --> <!-- 最近操作记录 --> <!-- <view class="recent-activity"> <view class="section-header"> <text class="section-title">最近操作</text> </view> <view class="activity-list"> <view class="activity-item"> <uni-icons type="arrow-up" size="32" color="#52c41a"></uni-icons> <view class="activity-detail"> <text class="activity-title">A4打印纸入库</text> <text class="activity-time">今天 10:30</text> </view> <text class="activity-quantity">+500箱</text> </view> --> <!-- 更多活动项 --> <!-- </view> --> </view> </view> </view> </template> <script> export default { data() { return { functions: [ { icon: 'plus', label: '新增入库', path: '/pages/tabbar/storageManagement/newOrder' }, { icon: 'minus', label: '新增出库', path: '/pages/outbound/create' }, { icon: 'list', label: '库存查询', path: '/pages/tabbar/storageManagement/selectOrder' }, // { icon: 'stats-bars', label: '库存统计', path: '/pages/report/stock' }, // { icon: 'alert', label: '库存预警', path: '/pages/warning/list' }, // { icon: 'person', label: '供应商管理', path: '/pages/supplier/list' } ] } }, methods: { navigateTo(path) { uni.navigateTo({ url: path }) }, navToInventory() { uni.navigateTo({ url: '/pages/inventory/list' }) } } } </script> <style lang="scss"> /* 全局样式保留 */ .warehouse-container { padding: 30rpx; background-color: #f5f7fa; min-height: 100vh; } /* 欢迎横幅样式保留 */ .welcome-banner { position: relative; height: 240rpx; background: linear-gradient(135deg, #5e8fff, #6b7de9); border-radius: 25rpx; margin-bottom: 40rpx; overflow: hidden; box-shadow: 0 15rpx 30rpx rgba(94, 143, 255, 0.35); .banner-content { padding: 40rpx 35rpx; position: relative; z-index: 2; } .welcome-title { display: flex; flex-direction: column; margin-bottom: 15rpx; } .welcome-text { font-size: 36rpx; color: rgba(255, 255, 255, 0.9); font-weight: 400; } .system-name { font-size: 46rpx; color: #ffffff; font-weight: bold; letter-spacing: 1rpx; } .welcome-subtitle { font-size: 28rpx; color: rgba(255, 255, 255, 0.85); } .banner-wave { position: absolute; bottom: 0; width: 100%; height: 80rpx; z-index: 1; } } /* 功能网格样式 */ .function-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 30rpx; margin-bottom: 50rpx; .grid-item { display: flex; flex-direction: column; align-items: center; padding: 35rpx 0; background: #ffffff; border-radius: 25rpx; box-shadow: 0 8rpx 25rpx rgba(0, 0, 0, 0.05); transition: all 0.3s ease; &:active { transform: scale(0.96); box-shadow: 0 4rpx 15rpx rgba(0, 0, 0, 0.08); } } .icon-wrapper { width: 100rpx; height: 100rpx; border-radius: 50%; background: rgba(94, 143, 255, 0.12); display: flex; justify-content: center; align-items: center; margin-bottom: 20rpx; } .item-label { font-size: 30rpx; color: #5a6573; font-weight: 500; } } /* 库存概览样式 */ // .inventory-section { // background: #ffffff; // border-radius: 25rpx; // padding: 35rpx; // margin-bottom: 40rpx; // box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.05); // .section-header { // display: flex; // justify-content: space-between; // align-items: center; // margin-bottom: 35rpx; // } // .section-title { // font-size: 36rpx; // font-weight: 600; // color: #2c3e50; // } // .view-all { // font-size: 28rpx; // color: #5e8fff; // font-weight: 500; // } // .inventory-metrics { // display: grid; // grid-template-columns: repeat(3, 1fr); // gap: 25rpx; // } // .metric-card { // background: #f8faff; // border-radius: 20rpx; // padding: 30rpx 20rpx; // text-align: center; // border: 1rpx solid #e6eeff; // &.warning { // background: #fff8f6; // border-color: #ffccc7; // } // .metric-value { // display: block; // font-size: 38rpx; // font-weight: 700; // color: #2c3e50; // margin-bottom: 10rpx; // } // .metric-label { // font-size: 26rpx; // color: #7a8599; // } // } // } /* 最近操作样式 */ // .recent-activity { // background: #ffffff; // border-radius: 25rpx; // padding: 35rpx; // box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.05); // .activity-list { // .activity-item { // display: flex; // align-items: center; // padding: 30rpx 0; // border-bottom: 1rpx solid #f0f2f7; // &:last-child { // border-bottom: none; // } // } // .activity-detail { // flex: 1; // margin-left: 25rpx; // } // .activity-title { // display: block; // font-size: 32rpx; // color: #2c3e50; // margin-bottom: 8rpx; // } // .activity-time { // font-size: 26rpx; // color: #a0a7b3; // } // .activity-quantity { // font-size: 32rpx; // font-weight: 600; // color: #52c41a; // } // } // } </style>
最新发布
11-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值