1 条题解

  • 0
    @ 2023-11-13 20:16:47

    给晚安学长出的题,种个草

    #include <iostream>
    using namespace std;
    const int N = 3e5 + 5;
    int a[N];
    int main()
    {
    	int t, n;
    	cin >> t;
    	while (t--)
    	{
    		cin >> n;
    		for (int i = 1; i <= n; i++)
    			cin >> a[i];
    		int ls = 0, t = 0, res = 1;
    		for (int i = 2; i <= n; i++)
    		{
    			if (a[i - 1] < a[i])
    				ls = 1;
    			else if (a[i - 1] > a[i])
    				ls = -1;
    			else
    				continue;
    			if (t != ls)
    				res++;
    			t = ls;
    		}
    		cout << res << endl;
    	}
    }
    

    信息

    ID
    930
    时间
    1000ms
    内存
    256MiB
    难度
    6
    标签
    递交数
    22
    已通过
    11
    上传者