• hdu 5701 中位数计数


    题目链接

    给一个数列, 每个数只出现一次。 问对于每个数, 有多少个区间是以它为中位数的。

    暴力统计, 对于每个数, 小于它的赋值-1, 大于它的赋值1. 然后暴力统计, 具体看代码。

    和bzoj一个题一样啊....

    #include <iostream>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <complex>
    #include <cmath>
    #include <map>
    #include <set>
    #include <string>
    #include <queue>
    #include <stack>
    #include <bitset>
    using namespace std;
    #define pb(x) push_back(x)
    #define ll long long
    #define mk(x, y) make_pair(x, y)
    #define lson l, m, rt<<1
    #define mem(a) memset(a, 0, sizeof(a))
    #define rson m+1, r, rt<<1|1
    #define mem1(a) memset(a, -1, sizeof(a))
    #define mem2(a) memset(a, 0x3f, sizeof(a))
    #define rep(i, n, a) for(int i = a; i<n; i++)
    #define fi first
    #define se second
    typedef complex <double> cmx;
    typedef pair<int, int> pll;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int mod = 1e9+7;
    const int inf = 1061109567;
    const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
    int l[16005], r[16005], a[8005], ans[8500], b[8005];
    int main()
    {
        int n;
        while(cin>>n) {
            for(int i = 1; i <= n; i++) {
                scanf("%d", &a[i]);
            }
            mem(ans);
            for(int i = 1; i <= n; i++) {
                memcpy(b, a, sizeof(a));
                for(int j = 1; j <= n; j++) {
                    if(i == j) {
                        b[i] = 0;
                        continue;
                    }
                    if(a[j]>a[i]) {
                        b[j] = 1;
                    } else {
                        b[j] = -1;
                    }
                }
                int sum = 0;
                mem(l);
                mem(r);
                l[n] = r[n] = 1;
                for(int j = i-1; j >= 1; j--) {
                    sum += b[j];
                    l[sum+n]++;
                }
                sum = 0;
                for(int j = i+1; j <= n; j++) {
                    sum += b[j];
                    r[sum+n]++;
                }
                for(int j = 0; j < 2*n; j++) {
                    ans[i] += l[j]*r[2*n-j];
                }
            }
            for(int i = 1; i < n; i++) {
                printf("%d ", ans[i]);
            }
            cout<<ans[n]<<endl;
        }
        return 0;
    }
    
    
  • 相关阅读:
    LSTM
    Realsense D435i
    ubuntu18 realsenseD435i
    net
    test
    LSTM Accuracy
    boost x64 lib
    E0443类模板 "std::unordered_set" 的参数太多
    PropertySheet
    freetype 编译
  • 原文地址:https://www.cnblogs.com/yohaha/p/5525280.html
Copyright © 2020-2023  润新知