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 ...
随机推荐
- linux tar.gz zip 减压 压缩命令
http://apps.hi.baidu.com/share/detail/37384818 download ADT link http://dl.google.com/android/ADT-0. ...
- handlebar的一些用法——个人使用总结
handlebar的一些用法 概述与介绍 Handlebars 是 JavaScript 一个语义模板库,通过对view和data的分离来快速构建Web模板.它采用"Logic-less t ...
- jquery expand
/** * jquery-expand-1.0.js * author:tww **/ (function(){ /** * jQuery fadeTo expand. **/ jQuery.fn._ ...
- oracle 11g 自己主动调整
--:自己主动调教计划 begin dbms_workload_repository.create_snapshot(); end; select /*+ result_cache */ coun ...
- hdu Color the ball
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 树状数组的 update的应用,逆序更新 代码: #include <stdio.h&g ...
- php+flash头像上传组件
有会员系统的站点一般都会有一个头像上传组件,一般做的最简单的是 这样的方式长处是代码写的简单,仅仅要推断图片大小和类型,然后更新数据库.可是用户体验不高.并且站点其它页面假设要使用较小的20X20或1 ...
- CSharp设计模式读书笔记(10):装饰模式(学习难度:★★★☆☆,使用频率:★★★☆☆)
装饰模式(Decorator Pattern): 动态地给一个对象增加一些额外的职责,就增加对象功能来说,装饰模式比生成子类实现更为灵活. 模式角色与结构: 示例代码: using System; u ...
- ExecutorService 建立一个多线程的线程池的步骤
ExecutorService 建立一个多线程的线程池的步骤: 线程池的作用: 线程池功能是限制在系统中运行的线程数. 依据系统的环境情况,能够自己主动或手动设置线程数量.达到执行的最佳效果:少了浪费 ...
- HTML5 Canvas简简单单实现手机九宫格手势密码解锁
原文:HTML5 Canvas简简单单实现手机九宫格手势密码解锁 早上花了一个半小时写了一个基于HTML Canvas的手势解锁,主要是为了好玩,可能以后会用到. 思路:根据配置计算出九个点的位置,存 ...
- PHP 使用用户自定义的比较函数对数组中的值进行排序
原文:PHP 使用用户自定义的比较函数对数组中的值进行排序 usort (PHP 4, PHP 5) usort — 使用用户自定义的比较函数对数组中的值进行排序 说明 bool ...