zoukankan      html  css  js  c++  java
  • Singing Everywhere ZOJ

    https://vjudge.net/problem/ZOJ-4107/origin

    https://vjudge.net/contest/395635#problem/H

    Baobao loves singing very much and he really enjoys a game called Singing Everywhere, which allows players to sing and scores the players according to their performance.

    Consider the song performed by Baobao as an integer sequence $a_1, a_2,dots,a_n$, where $a_i$ indicates the $i$-th note in the song. We say a note $a_k$ is a "voice crack" if $1 < k < n$, $a_{k-1} < a_k$ and $a_{k+1} < a_k$. The more voice cracks BaoBao sings, the lower score he gets.

    To get a higher score, BaoBao decides to delete at most one note in the song. What's the minimum number of times BaoBao sings a voice crack after this operation?

    Input

    There are multiple test cases. The first line of the input contains an integer $T$ (about 100), indicating the number of test cases. For each test case:

    The first line contains one integer $n$ ($1 leq n leq 10^{5}$), indicating the length of the song.

    The second line contains $n$ integers $a_1, a_2, dots, a_n$ ($-2^{31} leq a_i < 2^{31}$), indicating the song performed by BaoBao.

    It's guaranteed that at most 5 test cases have $n > 100$.

    Output

    For each test case output one line containing one integer, indicating the answer.

    Sample Input

    3
    6
    1 1 4 5 1 4
    7
    1 9 1 9 8 1 0
    10
    2 1 4 7 4 8 3 6 4 7
    

    Sample Output

    1
    0
    2
    

    Hint

    For the first sample test case, BaoBao does not need to delete a note. Because if he deletes no note, he will sing 1 voice crack (the 4th note), and no matter which note he deletes, he will also always sing 1 voice crack.

    For the second sample test case, BaoBao can delete the 3rd note, and no voice cracks will be performed. Yay!

    For the third sample test case, BaoBao can delete the 4th note, so that only 2 voice cracks will be performed (4 8 3 and 3 6 4).

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <cctype>
    #include <cmath>
    #include <cstdlib>
    #include <ctime>
    #include <deque>
    #include <iomanip>
    #include <list>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <vector>
    #include <iterator>
    #include <utility>
    #include <sstream>
    #include <limits>
    #include <numeric>
    #include <functional>
    using namespace std;
    #define gc getchar()
    #define mem(a) memset(a,0,sizeof(a))
    #define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl;
    
    #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    typedef long long ll;
    typedef unsigned long long ull;
    typedef long double ld;
    typedef pair<int,int> pii;
    typedef char ch;
    typedef double db;
    
    const double PI=acos(-1.0);
    const double eps=1e-6;
    const int inf=0x3f3f3f3f;
    const int maxn=1e5+10;
    const int maxm=100+10;
    const int N=1e6+10;
    const int mod=1e9+7;
    
    
    ll a[100005] = {0};
    int main()
    {
        int t = 0;
        cin >> t;
        while(t--)
        {
            int n = 0;
            cin >> n;
            for(int i = 0;i<n;i++)
            {
                cin >> a[i];
            }
            int mark = 0;
            int counter = 0;
            for(int i = 1;i<n-1;i++)
            {
                if(a[i]>a[i-1]&&a[i]>a[i+1])
                {
                    counter += 1;
                    if(     a[i-1] <= a[i-2] && a[i-1] <= a[i+1] && a[i+1] <= a[i+2]
                        ||  a[i+1] <= a[i+2] && a[i+1] <= a[i-1] && a[i-1] <= a[i-2])
                    {
                        mark = 1;
                    }
                    if(a[i+2]>a[i+1] && a[i+2]>a[i+3] && a[i]==a[i+2])
                    {
                        mark = 2;
                    }
                }
            }
            cout << counter - mark << endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    http请求工具类
    java订单号生成
    SpringUtil获取Spring容器对象
    git push的日志展示问题
    nodejs环境搭建,淘宝镜像cnpm
    csdn里面代码块颜色
    nginx简单使用
    vue项目打包后字体文件路径出错的解决办法
    VUE 爬坑之旅 -- 用 ES6 语法写一个工具类,并全局引用
    VUE 爬坑之旅 -- 用 ES6 语法写一个工具类,并全局引用
  • 原文地址:https://www.cnblogs.com/SutsuharaYuki/p/13813408.html
Copyright © 2011-2022 走看看