📜  Google Kick Round-D 问题(2020 年)

📅  最后修改于: 2022-05-13 01:58:30.174000             🧑  作者: Mango

Google Kick Round-D 问题(2020 年)

Isyana获得了连续 N 天在她当地主题公园的游客数量。第 i 天的访客人数为 VI。如果满足以下两个条件,一天就是破纪录的:

  1. 当天的访客人数严格大于前几天的访客人数。
  2. 要么是最后一天,要么当天的访客人数严格大于第二天的访客人数。

请注意,第一天可能是破纪录的一天。请帮助Isyana找出破纪录的天数。

输入:输入的第一行给出了测试用例的数量,T.T 测试用例紧随其后。每个测试用例都以包含整数 N 的行开始。第二行包含 N 个整数。第 i 个整数是 Vi。

输出:对于每个测试用例,输出一行包含 Case #x: y,其中 x 是测试用例编号(从 1 开始),y 是破纪录天数。

限制

时间限制:每个测试集 20 秒。

内存限制: 1GB。

1 ≤ T ≤ 100.
0 ≤ Vi ≤ 2 × 105.
Test set 1
1 ≤ N ≤ 1000.
Test set 2
1 ≤ N ≤ 2 × 105 for at most 10 test cases.
For the remaining cases, 1 ≤ N ≤ 1000.

样本

Input
Output
4
8
1 2 0 7 2 0 2 0
6
4 8 15 16 23 42
9
3 1 4 1 5 9 2 6 5
6
9 9 9 9 9 9
Case #1: 2
Case #2: 1
Case #3: 3
Case #4: 0

在示例案例 #1 中:以下粗体和带下划线的数字代表破纪录的天数:1 2 0 7 2 0 2 0。

在示例案例 #2 中:只有最后一天是破纪录的一天。

在示例案例 #3 中:第一天、第三天和第六天是破纪录的日子。

在示例案例 #4 中:没有破纪录的一天。

C++
#include
using namespace std;
 
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i>a[i];
    }
    int count=0;
    for(int i=1;ia[i-1]&&a[i]>a[i+1])
       {
 
           count++;
       }
    }
    cout<


C#
// C# program for the above approach
using System;
 
public class GFG{
     
    static int calculate(int[] arr, int n)
    {
        int cnt = 0;
       
        // initialising prevmax as -infinity
        int prevmax = Int32.MinValue;
     
        for (int i = 0; i < n; i++)
        {
           
            // check for condition 2
            if (i == n - 1) {
                if (arr[i] > prevmax)
                    cnt++;
            }
           
            // check for condition 1
            else if (arr[i] > prevmax && arr[i] > arr[i + 1]) {
                cnt++;
            }
            // update prevmax
            prevmax = Math.Max(prevmax, arr[i]);
        }
     
        return cnt;
    }
 
    // Driver Code
    static public void Main ()
    {
        int t = 1;
       
        // Taking the input for every test case
        while (t-- != 0)
        {
            int n = 9;
            int[] arr = { 3, 1, 4, 1, 5, 9, 2, 6, 5 };
            Console.Write(calculate(arr, n));
        }
    }
}
 
// This code is contributed by shubhamsingh10


Javascript


输出
3