Tanky WooRSS

BUCT OJ 1746 三逆数

01 Sep 2010
这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。

题目链接: http://coder.buct.edu.cn/oj/Problem.aspx?pid=1746

咋一看,以为又是水题,于是暴力之。。。。结果:TLE。。。。 再一看,可以优化: 先记录每个数,其后比其小的数。 再遍历每个数,其前面的比其大的数,加上先前的值,就OK了。。。

#include 
#include 
using namespace std;

int arr[1005];
int ans[1005];
int nCases;
int nNum;
int main()
{
    scanf("%d", &nCases;);
    while(nCases--)
    {
        memset(ans, 0, sizeof(ans));
        memset(arr, 0, sizeof(arr));
        scanf("%d", &nNum;);
        for(int i=0; iarr[i])
                    cnt += ans[i];
        printf("%d\n", cnt);

    }
    return 0;
}