Sicily 1685
来源:互联网 发布:mac book air能做什么 编辑:程序博客网 时间:2024/06/06 12:46
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 oddfor (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来做,等下我想下怎么做再写写~
- Sicily 1685
- sicily 1685 Missile
- Sicily 1685 Missile
- Sicily 1027
- sicily 1007
- sicily 1795
- sicily 1036
- sicily 1419
- sicily 1889
- sicily 1684
- sicily 1686
- sicily 1004
- sicily 1135
- sicily 1152
- sicily 1151
- sicily 1002
- sicily 1156
- sicily 1424
- 快速幂
- Hadoop学习之以全分布模式部署及问题
- hdu3306矩阵快速幂讲解
- python中使用POP协议
- C语言读写文件 -fopen、fread、fwrite
- Sicily 1685
- magento 设自定义选项,选择后价格变0
- SQl Server索引的总结
- BeanUtils包的使用
- C语言基础积累----动态数组
- 在CentOS6.4中设置VNC和FTP(一)
- Unity学习(四):Unity中的法线贴图和天空盒
- GDB中应该知道的几个调试方法
- magento URL大小写404解决