Judge Info

  • Memory Limit: 32768KB
  • Case Time Limit: 10000MS
  • Time Limit: 10000MS
  • Judger: Number Only Judger

Description

In the kingdom of frog, the most popular sport is jumping up and down. Frog likes to jump up(go higher) or jump down(go lower) but jump at the same height(not go higher,and not go lower). The frog king wants to have a sport path for jumping. The Sport path is made by same size blocks which may have different height,when the frog on the path, he can only jumps from one block to the next adjacent block. For frog, perfect path for jumping are those same-height-jumps can be avoided. The Sport path can be represented by an integer sequence which denotes the height of blocks.The length of the sport path is the numbers of integer in the sequence.

Task

Now, it is your turn. You will have a integer sequence represent a sport path, please output the longest perfect path we can find in the given sport path without cutting off.

Input

The first line of input contains , the number of test cases. There are two lines for each test case. The first line contains an integer number denoting how many blocks in the sport path. The second line contains N integer numbers (the height of blocks in the range [ − 100,100]).

Output

For each test case, print a line contains the solution.

Sample Input

2
8
1 1 3 5 5 7 9 8
5
1 2 3 4 5

Sample Output

4
5 解题思路:刚开始读不懂题意,以为是消除相同数和其本身,经过朋友说下才明白,原来是找最长的子串,但是遇到重复数字就开始新的字符串序列。
刚开始用了两个数组,之后用一个数组,而ACMser都不用开数组。
 #include <stdio.h>
#include <string.h>
int A[]; int main() {
int t,i,n,pre,max,count,min;
scanf("%d",&t);
while (t--) {
max = ;
scanf("%d",&n);
for (i=;i<n;i++) {
scanf("%d", &A[i]);
}
pre = ;
count =;
for (i=;i<n;++i) { if(A[i]==A[pre]){
if(count>max)
max = count;
count =;
continue;
}
count++;
pre=i;
}
min = count;
if (min > max)
max = min;
printf("%d\n",max);
}
}

朋友的做法(不开数组):

 #include <stdio.h>
int process(int n);
int main()
{
int testcase;
scanf("%d", &testcase);
while (testcase--) {
int n;
scanf("%d", &n);
printf("%d\n", process(n));
}
}
int process(int n)
{
int i, pre, cur;;
scanf("%d", &pre);
int cnt = , cur_max = ;
for (i = ; i != n; i++) {
scanf("%d", &cur);
if (cur == pre) {
if (cur_max < cnt)
cur_max = cnt;
cnt = ;
}
else {
cnt++;
}
pre = cur;
}
if (cur_max < cnt)
cur_max = cnt;
return cur_max;
}
 

SZU:A12 Jumping up and down的更多相关文章

  1. E - Super Jumping! Jumping! Jumping!

    /* Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popula ...

  2. Bungee Jumping[HDU1155]

    Bungee JumpingTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. Super Jumping! Jumping! Jumping!

    Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...

  4. DP专题训练之HDU 1087 Super Jumping!

    Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...

  5. hdu 1087 Super Jumping! Jumping! Jumping! 简单的dp

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  6. Super Jumping! Jumping! Jumping!——E

    E. Super Jumping! Jumping! Jumping! Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO forma ...

  7. TopCoder SRM 633 Div.2 500 Jumping

    题意:给一个点(x,y),给一些步长delta1,delta2...deltaN,问从(0,0)严格按照步长走完N步后能否正好到达(x,y)点. 解法:其实就是判断这些线段和(0,0)-(x,y)这条 ...

  8. HDU 1087 Super Jumping! Jumping! Jumping! 最大递增子序列

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. Jumping Cows_贪心

    Description Farmer John's cows would like to jump over the moon, just like the cows in their favorit ...

随机推荐

  1. express: command not found.

    npm install -g express 可是不行.全局模式不行. With the release of Express 4.0.0 it looks like you need to do s ...

  2. 使用sqlnet.ora限制IP访问

    他在最后一个超级遭遇了许多方法值,然后找到一个方法,在DB上限IP访问. http://blog.csdn.net/jacson_bai/article/details/18097805 ENV:   ...

  3. bigdata_批量机器执行通用脚本

    经常有这样的场景,需要批量验证一些配置或者机器,执行一些命令.例如  echo $PATH  等等 这里分享一个批量执行脚本 脚本名称 deployCommnd.sh 运行demo : sh depl ...

  4. Java和Flex积分误差(一个)

    1.错误叙述性说明 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency( ...

  5. jquery中DOM的操作方法

    先介绍几个比较简单的方法,不经常用到,做个记录 1. filter() 方法 顾名思义,filter是一个过滤器,如果给定表示 DOM 元素集合的 jQuery 对象,.filter() 方法会用匹配 ...

  6. elasticsearch的rest搜索--- 总述

    目录: 一.针对这次装B 的解释 二.下载,安装插件elasticsearch-1.7.0   三.索引的mapping 四. 查询 五.对于相关度的大牛的文档 一.针对这次装B 的解释  因为现在又 ...

  7. Robot Framework + appium 启动手机浏览器的两个方法(1)

    一.Open Browser启动 使用Selenium2Library的Open Browser方法,例子如下: browser=手机浏览器类型,如chrome 二.Open Application启 ...

  8. C#中ISpostback

    响应客户端控件时ispostback为true 代码: using System; using System.Collections.Generic; using System.Linq; using ...

  9. 访问Ice-Pick Lodge:假设公众筹款网站Kickstarter在成功

    Xsolla非常高兴採訪了来自莫斯科的工作室 Ice-Pick Lodge的Golubeva.数天前,该公司已成功在Kickstarter上募集资金,创造出最知名的游戏"Pathologic ...

  10. Facebook HHVM 和 Hack 手册----1.什么是Hack?

    什么是Hack? Hack 是一种基于HHVM(HipHop VM 是Facebook推出的用来执行PHP代码的虚拟机,它是一个PHP的JIT编译器,同时具有产生快速代码和即时编译的优点)的新型编程语 ...