---
# System prepended metadata

title: UVA 11240 ★★
tags: [CPE 二顆星]

---

## 題目
[點我](https://onlinejudge.org/external/112/11240.pdf)

## 演算法
greedy

## 程式碼
```cpp=
#include <bits/stdc++.h>

using namespace std;

void func(){
    int n;
    cin >> n;
    int arr[30001];
    for(int i = 1 ; i <= n ; i++){
        cin >> arr[i];
    }
    
    
    bool down = 1;
    int val = arr[1];
    int cnt = 1;
    for(int i = 2 ; i <= n ; i++){
        if(down){
            if(arr[i] < val){
                cnt++;
                val = arr[i];
                down = !down;
            }
            else val = arr[i];
        } else {
            if(arr[i] > val){
                cnt++;
                val = arr[i];
                down = !down;
            }
            else val = arr[i];
        }
    }
    
    cout << cnt << endl;
}

int main()
{
    
    int t;
    cin >> t;
    for(int i = 1 ; i <= t ; i++){
        func();
    }
    

    return 0;
}

```

