SZU:A12 Jumping up and down
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的更多相关文章
- E - Super Jumping! Jumping! Jumping!
/* Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popula ...
- Bungee Jumping[HDU1155]
Bungee JumpingTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Super Jumping! Jumping! Jumping!
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...
- DP专题训练之HDU 1087 Super Jumping!
Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...
- hdu 1087 Super Jumping! Jumping! Jumping! 简单的dp
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Super Jumping! Jumping! Jumping!——E
E. Super Jumping! Jumping! Jumping! Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO forma ...
- TopCoder SRM 633 Div.2 500 Jumping
题意:给一个点(x,y),给一些步长delta1,delta2...deltaN,问从(0,0)严格按照步长走完N步后能否正好到达(x,y)点. 解法:其实就是判断这些线段和(0,0)-(x,y)这条 ...
- HDU 1087 Super Jumping! Jumping! Jumping! 最大递增子序列
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Jumping Cows_贪心
Description Farmer John's cows would like to jump over the moon, just like the cows in their favorit ...
随机推荐
- XP下类似%windir% %userprofile% 的变量的说明(转)
在一些批处理或者系统技巧操作教程文章中,我们常常会看到一些形如 %windir% 或者 %systemdrive% 的变量.这些变量都代表着什么含义呢?下面小技巧之家为大家整理了在Windows XP ...
- hdu4864Task(馋)
主题链接: 啊哈哈.点我 题目: Task Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- VS解决方案创建
示例VS解决方案的创建(一) 进行项目开发的第一步,是创建出适合自己团队习惯的VS解决方案,虽然我已经提供了项目示例,但毕竟是我创建的,你直接使用可能并不合适,另外你如果尝试模仿重新创建该示例,中 ...
- 多校训练赛2 ZCC loves cards
ZCC loves cards Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 从头开始学JavaScript (五)——操作符(二)
原文:从头开始学JavaScript (五)--操作符(二) 一.乘性操作符 1.乘法:* 乘法操作符的一些特殊规则: 如果操作数都是数值,按照常规的乘法计算,如果乘积超过了ECMAscri ...
- linux系统管理命令--系统测试工具
1.tcpdump -n 使用IP地址表示主机,而不是主机名的:使用数字port号码,而不是服务名 -i 指定要监听的网卡接口, "-i any"表示抓取全部网卡接口上的数 ...
- 如何将经纬度利用Google Map API显示C# VS2005 Sample Code
原文 如何将经纬度利用Google Map API显示C# VS2005 Sample Code 日前写了一篇如何用GPS抓取目前所在,并回传至资料库储存,这篇将会利用这些回报的资料,将它显示在地图上 ...
- iOS--Swift开发中的单例设计模式
最近在开发一个小的应用,遇到了一些Objective-c上面常用的单例模式,但是swift上面还是有一定区别的,反复倒来倒去发现不能按常理(正常的oc to swift的方式)出牌,因此搜索了一些帖子 ...
- Java-DES算法加密解密工具类
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import ...
- Linq to Sql:N层应用中的查询(下) : 根据条件进行动态查询
原文:Linq to Sql:N层应用中的查询(下) : 根据条件进行动态查询 如果允许在UI层直接访问Linq to Sql的DataContext,可以省去很多问题,譬如在处理多表join的时候, ...