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;
}
最新文章
- 学习python
- 从零开始编写自己的C#框架(18)——Web层后端权限模块——菜单管理
- session和cookie的区别
- 网络编程之socket
- python统计列表内元素个数
- 51nod 1013快速幂 + 费马小定理
- [转]Linux下的lds链接脚本详解
- Android拍照保存在系统相册不显示的问题
- 【转】Xcode7.1环境下上架iOS App到AppStore 流程 (Part 三)
- 查看ip地址信息和配置临时ip
- IIS下 Yii Url重写
- Hive插数据报错
- 进制转换,杭电0j-2031
- 基于junit的单元测试类编写
- CodeVS1288埃及分数(IDA*)
- 使用viewport中的vm来适配移动端页面
- 使用 udev 高效、动态地管理 Linux 设备文件
- MovieLens电影数据分析
- (2)Django入门
- How to Check if Linux (Ubuntu, Fedora Redhat, CentOS) is 32-bit or 64-bit
热门文章
- Systrace
- React学习系列
- hdu Jungle Roads(最小生成树)
- MySql创建一个存储过程
- 各大oj题目分类(转)
- 浅谈JavaScript中的字符串操作
- .NET 对象序列化和系列化德
- ar命令提取.a时刻,一个错误 is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
- ListView排序并隔色显示
- [CLR via C#]1.6 Framework类库~1.9与非托管代码的互操作性