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. Nyoj 吝啬的国度(图论&&双DFS)

    描述在一个吝啬的国度里有N个城市,这N个城市间只有N-1条路把这个N个城市连接起来.现在,Tom在第S号城市,他有张该国地图,他想知道如果自己要去参观第T号城市,必须经过的前一个城市是几号城市(假设你 ...

  2. linux_后台启动多个java -jar 程序,及关闭

    启动脚本 startup.sh #!/bin/bash x=$(($)) )) do java -jar /home/chenpenghui/crawler/crawler-hb/StartUpIp. ...

  3. Linux应用环境

    转载Linux应用环境 阅读目录 引言 使用 Linux 的一些困难和解决方法 我眼中的Linux哲学总纲 我这一系列随笔中展现出的Linux哲学 Linux之得和Linux之失 总结 回到顶部 引言 ...

  4. netty 3.9.2 UDP协议服务器和客户端DEMO

    说明:基于netty 3.9.2的udp协议实现的(如果你使用的版本是4.X或5.X,请参考其他方法):程序的逻辑结构是,客户端发送给服务端一串数据,服务器端返回给客户端“A”.在进行游戏开发时需要对 ...

  5. 通讯录C++console application

    #include<iostream> #include<fstream> #include<string> #include<cstring> #inc ...

  6. .net mvc4 从客户端中检测到有潜在危险的 Request.Form 值

    [ValidateInput(false)] 即可, 网上说什么Web.Config 里面改,一点用都没有 [HttpPost] [ActionName("Edit")] [Val ...

  7. 如何使用Visual Studio 2013 开发PHP5.6项目

    原文如何使用Visual Studio开发PHP项目 在windows下开发php除了记事本 DW 以及一帮Zend studio,Eclipse,NetBeans之流以外,个人感觉还是vsiual ...

  8. [推荐]ORACLE PL/SQL编程之五:异常错误处理(知已知彼、百战不殆)

    原文:[推荐]ORACLE PL/SQL编程之五:异常错误处理(知已知彼.百战不殆) [推荐]ORACLE PL/SQL编程之五: 异常错误处理(知已知彼.百战不殆) 继上三篇:ORACLE PL/S ...

  9. 第三记“晋IT”分享成长沙龙

    2014年8月17日下午4点-7点,第三期"晋IT"分享成长沙龙在太原大自然蒙特梭利幼儿园多功能厅成功举办. 8月17日下午两点.小编领先来到场地,提前探訪一下准备情况. &quo ...

  10. Visual Studio 2013进行单元测试

    使用Visual Studio 2013进行单元测试--初级篇   1.打开VS2013 --> 新建一个项目.这里我们默认创建一个控制台项目.取名为UnitTestDemo 2.在解决方案里面 ...