• HDU 5701 中位数计数


    暴力。

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<map>
    #include<vector>
    #include<algorithm>
    using namespace std;
    
    const int maxn=8000+10;
    int n;
    int a[maxn],b[maxn];
    int L[17000],R[17000];
    vector<int>ans;
    
    int main()
    {
        while(~scanf("%d",&n))
        {
            for(int i=1; i<=n; i++) scanf("%d",&a[i]);
    
            ans.clear();
            for(int i=1; i<=n; i++)
            {
                memset(b,0,sizeof b);
                for(int j=1; j<=n; j++)
                {
                    if(a[j]<a[i]) b[j]=-1;
                    else if(a[j]>a[i]) b[j]=1;
                }
    
                memset(L,0,sizeof L);
                memset(R,0,sizeof R);
    
                for(int j=i-1; j>=1; j--)
                {
                    b[j]=b[j]+b[j+1];
                    L[b[j]+8000]++;
                }
    
                for(int j=i+1; j<=n; j++)
                {
                    b[j]=b[j]+b[j-1];
                    R[b[j]+8000]++;
                }
    
                int tot=0;
                for(int j=-8000; j<=8000; j++)
                    tot=tot+L[j+8000]*R[-j+8000];
    
                tot=tot+L[0+8000];
                tot=tot+R[0+8000];
    
                ans.push_back(tot+1);
            }
            for(int i=0; i<ans.size(); i++)
            {
                printf("%d",ans[i]);
                if(i<ans.size()-1) printf(" ");
                else printf("
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    11.13 同步异步协程
    GIL及进程池
    线程
    守护进程-互斥锁-IPC
    进程
    网络编程
    异常的处理
    面向对象编程2
    第一章 python学习,个人对计算机硬件的一些理解
    ActiveReports之直接打印报表
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5519177.html
Copyright © 2020-2023  润新知