Sicily 1685

wa了几次,发现是题目意思没搞懂。

题目:

Description

Long, long ago, country A invented a missile system to destroy the missiles from their enemy. That system can launch only one missile to destroy multiple missiles if the heights of all the missiles form a non-decrease sequence.

But recently, the scientists found that the system is not strong enough. So they invent another missile system. The new system can launch one single missile to destroy many more enemy missiles. Basically, the system can destroy the missile from near to far. When the system is begun, it chooses one enemy missile to destroy, and then destroys a missile whose height is lower and farther than the first missile. The third missile to destroy is higher and farther than the second missile… the odd missile to destroy is higher and farther than the previous one, and the even missile to destroy is lower and farther than the previous one.

Now, given you a list of the height of missiles from near to far, please find the most missiles that can be destroyed by one missile launched by the new system.

Input

The input contains multiple test cases.

In each test case, first line is an integer n (0<n<=1000), which is the number of missiles to destroy. Then follows one line which contains n integers (<=10^9), the height of the missiles followed by distance.

The input is terminated by n=0.

Output

For each case, print the most missiles that can be destroyed in one line.

Sample Input

45 3 2 431 1 10

Sample Output

31

解法:

// Copyright <lijiancheng> [2014]
// Sicily 1685
#include <iostream>
using namespace std;

int main() {
	int arr[1000];
	int ans;
	int t;
	while (cin >> t && t) {
		ans = 1;
		for (int i = 0; i < t; i++) {
			cin >> arr[i];
		}
		int temp = 1;
		int start = 1; // 1 means the even, 0 means odd
		for (int i = 0; i < t-1; i++) {
			start = 1;
			for (int j = i+1; j < t; j++) {
				if(start) {
					if (arr[j] < arr[j-1]) {
						temp++;
						start = 0;
					}
//					else {
//						break; // 题目说只要后面的比前面的further就好了,所以不用break 下面同理。
//					}
				}
				else {
					if (arr[j] > arr[j-1]) {
						temp++;
						start = 1;
					}
//					else {
//						break;
//					}
				}
			}
			if (temp > ans) {
				ans = temp;
			}
			temp = 1;
		}
		cout << ans << endl;
	}
}

这里估计也可以用dp来做,等下我想下怎么做再写写~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值