LA4329 Ping pong

N (3<N<20000) ping pong players live along a west-east street(consider the street as a line segment). Each player has a unique skill rank. To improve their skill rank, they often compete with each other. If two players want to compete, they must choose a referee among other ping pong players and hold the game in the referee's house. For some reason, the contestants can't choose a referee whose skill rank is higher or lower than both of theirs. The contestants have to walk to the referee's house, and because they are lazy, they want to make their total walking distance no more than the distance between their houses. Of course all players live in different houses and the position of their houses are all different. If the referee or any of the two contestants is different, we call two games different. Now is the problem: how many different games can be held in this ping pong street?
Input 


The first line of the input contains an integer T (1$ \le$T$ \le$20) , indicating the number of test cases, followed by T lines each of which describes a test case.
Every test case consists of N + 1 integers. The first integer is N, the number of players. Then N distinct integers a1, a2...aNfollow, indicating the skill rank of each player, in the order of west to east ( 1$ \le$ai$ \le$100000 , i = 1...N ).
Output 


For each test case, output a single line contains an integer, the total number of different games.
Sample Input 


1
3 1 2 3
Sample Output 

1



#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 20000+20
#define maxm 100000+20
using namespace std;
#define mem0(a) memset(a,0,sizeof(a))
int a[maxn],c[maxn],d[maxn],e[maxm];




void add(int x){
    while( x <= maxm) {
        e[x]+= 1;
        x+= x&(-x);// lowbit(x)=x&(-x)
    }
}
int sum(int x){
    int ans = 0 ;
    while(x){
        ans += e[x];
        x -= x&(-x);
    }
    return ans ;
}




int main(){
    int t;
    scanf("%d",&t);
    while(t--){ //有T组测试数据
        int n ;
        scanf("%d",&n);//每组数据有n个数
        mem0(a);mem0(c);//初始化标记数组c
        mem0(d);mem0(e);
        for(int i = 1 ; i <= n ; i++){ 
            scanf("%d",&a[i]); //使每一个比a[i]大的数加1,保存在相应的e[i]中
            add(a[i]);
            c[i] = sum(a[i]-1);//sum函数是求比a[i]小的数之和
        } //用数组c[i]保存比a[i]小的数之和,
        
        mem0(e);
/*
注:只要比a[i]大的数,都加1;反之c[i]=n就表示在i号数之前共有n个数比它小
但在求和时要减一,不能包括它本身
*/   
        //从后向前考虑每一个比t[i]大的数
        for(int i = n ; i >= 1 ; i--){
            add(a[i]);
            d[i]=sum(a[i]-1);
        }x
        long long ans = 0 ;
        for(int i = 1 ; i <= n ; i++){
            ans += (long long)(c[i])*(n-i-d[i]) + (long long )d[i]*(i-1-c[i]);
        }
        printf("%lld\n",ans);
    }
    return 0;<span style="font-family: Arial, Helvetica, sans-serif;">}</span>




HD_RESULT mem_init(void) { HD_RESULT ret; HD_COMMON_MEM_INIT_CONFIG mem_cfg = {0}; #ifdef DLA_SUPPORT int model_size = 0; #endif #if defined(DLA_SUPPORT) || defined(DUAL_SENSOR) || defined(SENSOR_RESOLUTION_8MP) || defined(SENSOR_RESOLUTION_5MP) \ || defined(AIISP_ENABLED) || defined(SENSOR_RESOLUTION_4MP) || defined(SENSOR_RESOLUTION_12MP) || defined(MEDIA_PIPELINE_BASE_PTZ5425) int index = 0; #endif #ifdef BINOCULOR_AVS int i = 0; int vsp_dev_cnt = MAX_STICHING_CHN_CNT; int vsp_src_cnt = MIN_AVS_SRC_CHAN_NUM; int max_ovlp_width = 0; #endif // config common pool (main) mem_cfg.pool_info[0].type = HD_COMMON_MEM_COMMON_POOL; // 双目拼接机型需要使用左右目YUV420原图做色差校正检验(产测模式)和自动拼接,不压缩 #ifdef BINOCULOR_AVS mem_cfg.pool_info[0].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(ALIGN_CEIL_16(VDO_SIZE_W), ALIGN_CEIL_16(VDO_SIZE_H), HD_VIDEO_PXLFMT_YUV420); // align to 16 for rotate buffer #else if (YUV_COMPRESS_ENABLE == 1) { mem_cfg.pool_info[0].blk_size = DBGINFO_BUFSIZE()+VDO_NVX_BUFSIZE(ALIGN_CEIL_16(VDO_SIZE_W), ALIGN_CEIL_16(VDO_SIZE_H), HD_VIDEO_PXLFMT_YUV420); // align to 16 for rotate buffer } else { mem_cfg.pool_info[0].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(ALIGN_CEIL_16(VDO_SIZE_W), ALIGN_CEIL_16(VDO_SIZE_H), HD_VIDEO_PXLFMT_YUV420); // align to 16 for rotate buffer } #endif #ifdef DUAL_SENSOR mem_cfg.pool_info[0].blk_cnt = 5; #else mem_cfg.pool_info[0].blk_cnt = 1; #endif #ifdef HDR_MODE_SUPPORT if (g_hdr_enabled) { mem_cfg.pool_info[0].blk_cnt += 1; } #endif #ifdef AIISP_ENABLED mem_cfg.pool_info[0].blk_cnt += 2; #endif #ifdef SENSOR_RESOLUTION_8MP mem_cfg.pool_info[0].blk_cnt = 3; #elif defined SENSOR_RESOLUTION_12MP mem_cfg.pool_info[0].blk_cnt = 3; #elif defined SENSOR_RESOLUTION_5MP mem_cfg.pool_info[0].blk_cnt = 2; #elif defined MEDIA_PIPELINE_BASE_PTZ5425 mem_cfg.pool_info[0].blk_cnt = 3; #endif #ifdef BINOCULOR_AVS mem_cfg.pool_info[0].blk_cnt += (3 * vsp_src_cnt); #endif mem_cfg.pool_info[0].ddr_id = DDR_ID0; // config common pool (sub) mem_cfg.pool_info[1].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[1].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(ALIGN_CEIL_16(SUB_VDO_SIZE_W), ALIGN_CEIL_16(SUB_VDO_SIZE_H), HD_VIDEO_PXLFMT_YUV420); // align to 16 for rotate buffer #ifdef DUAL_SENSOR mem_cfg.pool_info[1].blk_cnt = 6; #elif MEDIA_PIPELINE_BASE_PTZ5425 mem_cfg.pool_info[1].blk_cnt = 4; #else mem_cfg.pool_info[1].blk_cnt = 4; #endif mem_cfg.pool_info[1].ddr_id = DDR_ID0; // TODO:if needed // config common pool (jpeg) mem_cfg.pool_info[2].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[2].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(ALIGN_CEIL_16(JPEG_VDO_SIZE_W), ALIGN_CEIL_16(JPEG_VDO_SIZE_H), HD_VIDEO_PXLFMT_YUV420); #if (defined SENSOR_RESOLUTION_4MP || defined SENSOR_RESOLUTION_8MP || defined SENSOR_RESOLUTION_12MP) && (defined HDR_MODE_SUPPORT) if (g_hdr_enabled) { mem_cfg.pool_info[2].blk_cnt = 2; } else { mem_cfg.pool_info[2].blk_cnt = 1; } #else mem_cfg.pool_info[2].blk_cnt = 1; #endif mem_cfg.pool_info[2].ddr_id = DDR_ID0; /* 由于人脸抓拍的处理耗时较久,因此识别流通道及其扩展通道JPEG需要加大一块缓存,防止get blk failed */ if(g_face_enabled) { mem_cfg.pool_info[2].blk_cnt += 1; } // config common pool (divp) mem_cfg.pool_info[3].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[3].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(ISP_FRAME_WIDTH, ISP_FRAME_HEIGHT, HD_VIDEO_PXLFMT_YUV420); #ifdef DUAL_SENSOR mem_cfg.pool_info[3].blk_cnt = 2; #else mem_cfg.pool_info[3].blk_cnt = 1; #endif mem_cfg.pool_info[3].ddr_id = DDR_ID0; // user pool for ao mem_cfg.pool_info[4].type = HD_COMMON_MEM_USER_POOL_BEGIN; mem_cfg.pool_info[4].blk_size = 0x1000; mem_cfg.pool_info[4].blk_cnt = 1; mem_cfg.pool_info[4].ddr_id = DDR_ID0; #ifdef DUAL_SENSOR // config common pool (osg--main-time) mem_cfg.pool_info[5].type = HD_COMMON_MEM_OSG_POOL; mem_cfg.pool_info[5].blk_size = get_stampsize(STRM_ID_MAIN,1); mem_cfg.pool_info[5].blk_cnt = 2; mem_cfg.pool_info[5].ddr_id = DDR_ID0; // config common pool (osg--main) mem_cfg.pool_info[6].type = HD_COMMON_MEM_OSG_POOL; mem_cfg.pool_info[6].blk_size = get_stampsize(STRM_ID_MAIN,0); mem_cfg.pool_info[6].blk_cnt = 6; mem_cfg.pool_info[6].ddr_id = DDR_ID0; // config common pool (osg--minor-time) mem_cfg.pool_info[7].type = HD_COMMON_MEM_OSG_POOL; mem_cfg.pool_info[7].blk_size = get_stampsize(STRM_ID_MINOR,1); mem_cfg.pool_info[7].blk_cnt = 2; mem_cfg.pool_info[7].ddr_id = DDR_ID0; // config common pool (osg--minor) mem_cfg.pool_info[8].type = HD_COMMON_MEM_OSG_POOL; mem_cfg.pool_info[8].blk_size = get_stampsize(STRM_ID_MINOR,0); mem_cfg.pool_info[8].blk_cnt = 6; mem_cfg.pool_info[8].ddr_id = DDR_ID0; #else mem_cfg.pool_info[5].type = HD_COMMON_MEM_OSG_POOL; mem_cfg.pool_info[5].blk_size = get_stampsize(STRM_ID_MAIN,1); mem_cfg.pool_info[5].blk_cnt = 1; mem_cfg.pool_info[5].ddr_id = DDR_ID0; // config common pool (osg--main) mem_cfg.pool_info[6].type = HD_COMMON_MEM_OSG_POOL; mem_cfg.pool_info[6].blk_size = get_stampsize(STRM_ID_MAIN,0); /*OSD PTZ显示需额外占用一个内存块*/ #ifdef SUPPORT_PTZ_OSD mem_cfg.pool_info[6].blk_cnt = 4; #else mem_cfg.pool_info[6].blk_cnt = 3; #endif mem_cfg.pool_info[6].ddr_id = DDR_ID0; // config common pool (osg--minor-time) mem_cfg.pool_info[7].type = HD_COMMON_MEM_OSG_POOL; mem_cfg.pool_info[7].blk_size = get_stampsize(STRM_ID_MINOR,1); mem_cfg.pool_info[7].blk_cnt = 1; mem_cfg.pool_info[7].ddr_id = DDR_ID0; // config common pool (osg--minor) mem_cfg.pool_info[8].type = HD_COMMON_MEM_OSG_POOL; mem_cfg.pool_info[8].blk_size = get_stampsize(STRM_ID_MINOR,0); /*OSD PTZ显示需额外占用一个内存块*/ #ifdef SUPPORT_PTZ_OSD mem_cfg.pool_info[8].blk_cnt = 4; #else mem_cfg.pool_info[8].blk_cnt = 3; #endif mem_cfg.pool_info[8].ddr_id = DDR_ID0; #endif // config common pool mem_cfg.pool_info[9].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[9].blk_size = 0x38C0; mem_cfg.pool_info[9].blk_cnt = 4; mem_cfg.pool_info[9].ddr_id = DDR_ID0; #if defined(DUAL_SENSOR) || defined(SENSOR_RESOLUTION_8MP) || defined(SENSOR_RESOLUTION_5MP) \ || defined(AIISP_ENABLED) || defined(SENSOR_RESOLUTION_4MP) || defined(SENSOR_RESOLUTION_12MP) || defined(MEDIA_PIPELINE_BASE_PTZ5425) index = 10; #endif #ifdef DLA_SUPPORT // config common pool (dla) mem_cfg.pool_info[10].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[10].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(DLA_FRAME_WIDTH, DLA_FRAME_HEIGHT, HD_VIDEO_PXLFMT_YUV420); #ifdef DUAL_SENSOR mem_cfg.pool_info[10].blk_cnt = 2; #elif defined SENSOR_RESOLUTION_8MP mem_cfg.pool_info[10].blk_cnt = 2; #elif defined SENSOR_RESOLUTION_12MP mem_cfg.pool_info[10].blk_cnt = 2; #elif defined MEDIA_PIPELINE_BASE_PTZ5425 mem_cfg.pool_info[10].blk_cnt = 1; #else mem_cfg.pool_info[10].blk_cnt = 1; #endif mem_cfg.pool_info[10].ddr_id = DDR_ID0; index = 11; //模型加载 #define UTILS_MAX(a, b) (((a) > (b)) * (a) + ((a) <= (b)) * (b)) int size_0 = _getsize_model(OBJ_DET_MODEL_FILE_NAME); int size_90 = _getsize_model(OBJ_DET_MODEL_FILE_NAME_90); int size_270 = _getsize_model(OBJ_DET_MODEL_FILE_NAME_270); int size_fd_0 = _getsize_model(OBJ_DET_MODEL_FILE_NAME_FD); int size_fd_90 = _getsize_model(OBJ_DET_MODEL_FILE_NAME_FD_90); int size_fd_270 = _getsize_model(OBJ_DET_MODEL_FILE_NAME_FD_270); int max_blk_size = UTILS_MAX(size_0, size_90); max_blk_size = UTILS_MAX(max_blk_size, size_270); max_blk_size = UTILS_MAX(max_blk_size, size_fd_0); max_blk_size = UTILS_MAX(max_blk_size, size_fd_90); max_blk_size = UTILS_MAX(max_blk_size, size_fd_270); printf("**************** max_blk_size:%d *****************", max_blk_size); model_size = max_blk_size; if (model_size > 0) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_USER_DEFINIED_POOL; mem_cfg.pool_info[index].blk_size = model_size; mem_cfg.pool_info[index].blk_cnt = 1; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; } /* 通过宏确定能加载的人头最大模型大小, 按照最大申请 */ int size_head0 = _getsize_model(HEAD_DET_MODEL_FILE_NAME); int size_head90 = _getsize_model(HEAD_DET_MODEL_FILE_NAME_90); int max_head_blk_size = size_head0 > size_head90 ? size_head0 : size_head90; model_size = max_head_blk_size; if (model_size > 0) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_USER_DEFINIED_POOL; mem_cfg.pool_info[index].blk_size = model_size; mem_cfg.pool_info[index].blk_cnt = 1; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; } model_size = _getsize_model(PCLS_MODEL_FILE_NAME); if (model_size > 0) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_USER_DEFINIED_POOL; mem_cfg.pool_info[index].blk_size = model_size; mem_cfg.pool_info[index].blk_cnt = 1; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; } #ifdef DLA_REC_STREAM_SUPPORT if (g_people_enabled) { //PR model_size = _getsize_model(PR_MODEL_FILE_NAME); if (model_size > 0) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_USER_DEFINIED_POOL; mem_cfg.pool_info[index].blk_size = model_size; mem_cfg.pool_info[index].blk_cnt = 1; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; } //PKP model_size = _getsize_model(PKP_MODEL_FILE_NAME); if (model_size > 0) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_USER_DEFINIED_POOL; mem_cfg.pool_info[index].blk_size = model_size; mem_cfg.pool_info[index].blk_cnt = 1; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; } } if (g_vehicle_enabled) { //VTC model_size = _getsize_model(VTC_MODEL_FILE_NAME); if (model_size > 0) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_USER_DEFINIED_POOL; mem_cfg.pool_info[index].blk_size = model_size; mem_cfg.pool_info[index].blk_cnt = 1; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; } } #endif #ifdef DLA_FSS_SUPPORT if (g_face_enabled) { model_size = _getsize_model(FACE_REC_MODEL_FILE_NAME); if (model_size > 0) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_USER_DEFINIED_POOL; mem_cfg.pool_info[index].blk_size = model_size; mem_cfg.pool_info[index].blk_cnt = 1; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; } model_size = _getsize_model(FACE_LANDMARK_MODE_FILE_NAME); if (model_size > 0) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_USER_DEFINIED_POOL; mem_cfg.pool_info[index].blk_size = model_size; mem_cfg.pool_info[index].blk_cnt = 1; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; } } #endif #ifdef VENC_YUV2JPG_SUPPORT if (g_face_enabled || g_people_enabled || g_vehicle_enabled || g_head_detection_enabled) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_USER_DEFINIED_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(VENC_JPEG_MAX_WIDTH, VENC_JPEG_MAX_HEIGHT, HD_VIDEO_PXLFMT_YUV420); mem_cfg.pool_info[index].blk_cnt = 1; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; } #endif #ifdef DLA_REC_STREAM_SUPPORT if (g_face_enabled || g_people_enabled || g_vehicle_enabled) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(DLA_REC_FRAME_WIDTH, DLA_REC_FRAME_HEIGHT, HD_VIDEO_PXLFMT_YUV420); mem_cfg.pool_info[index].blk_cnt = 2;/* 1个block用于识别流,1个block用于jpeg扩展通道, 由于JPEG的实际帧率较低,可以视为基本上不占用 */ mem_cfg.pool_info[index].ddr_id = DDR_ID0; } /* 由于人脸抓拍的处理耗时较久,因此识别流通道及其扩展通道JPEG需要加大一块缓存,防止get blk failed */ if(g_face_enabled) { mem_cfg.pool_info[index].blk_cnt += 1; } index++; #endif #endif #ifdef DUAL_SENSOR // config common pool (cap) mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_RAW_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H, CAP_OUT_FMT) +VDO_CA_BUF_SIZE(CA_WIN_NUM_W, CA_WIN_NUM_H) +VDO_LA_BUF_SIZE(LA_WIN_NUM_W, LA_WIN_NUM_H); mem_cfg.pool_info[index].blk_cnt = 2; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; #endif #if (defined SENSOR_RESOLUTION_8MP) || (defined SENSOR_RESOLUTION_12MP) // config common pool (cap) mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_RAW_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H, CAP_OUT_FMT) +VDO_CA_BUF_SIZE(CA_WIN_NUM_W, CA_WIN_NUM_H) +VDO_LA_BUF_SIZE(LA_WIN_NUM_W, LA_WIN_NUM_H); mem_cfg.pool_info[index].blk_cnt = 3; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_NRX_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H, CAP_OUT_FMT) +VDO_CA_BUF_SIZE(CA_WIN_NUM_W, CA_WIN_NUM_H) +VDO_LA_BUF_SIZE(LA_WIN_NUM_W, LA_WIN_NUM_H); mem_cfg.pool_info[index].blk_cnt = 3; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; #endif #ifdef SENSOR_RESOLUTION_5MP // config common pool (cap) mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_RAW_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H, CAP_OUT_FMT) +VDO_CA_BUF_SIZE(CA_WIN_NUM_W, CA_WIN_NUM_H) +VDO_LA_BUF_SIZE(LA_WIN_NUM_W, LA_WIN_NUM_H); mem_cfg.pool_info[index].blk_cnt = 2; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; if(g_hdr_enabled) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_NRX_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H, CAP_OUT_FMT) +VDO_CA_BUF_SIZE(CA_WIN_NUM_W, CA_WIN_NUM_H) +VDO_LA_BUF_SIZE(LA_WIN_NUM_W, LA_WIN_NUM_H); mem_cfg.pool_info[index].blk_cnt = 2; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; } #endif #ifdef MEDIA_PIPELINE_BASE_PTZ5425 // config common pool (cap) mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_RAW_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H, CAP_OUT_FMT) +VDO_CA_BUF_SIZE(CA_WIN_NUM_W, CA_WIN_NUM_H) +VDO_LA_BUF_SIZE(LA_WIN_NUM_W, LA_WIN_NUM_H); mem_cfg.pool_info[index].blk_cnt = 2; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; if(g_hdr_enabled) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_RAW_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H, CAP_OUT_FMT) +VDO_CA_BUF_SIZE(CA_WIN_NUM_W, CA_WIN_NUM_H) +VDO_LA_BUF_SIZE(LA_WIN_NUM_W, LA_WIN_NUM_H); mem_cfg.pool_info[index].blk_cnt = 2; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; } #endif #if defined(SENSOR_RESOLUTION_4MP) || defined(BINOCULOR_AVS) /*dram mode*/ mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_RAW_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H, CAP_OUT_FMT) +VDO_CA_BUF_SIZE(CA_WIN_NUM_W, CA_WIN_NUM_H) +VDO_LA_BUF_SIZE(LA_WIN_NUM_W, LA_WIN_NUM_H); mem_cfg.pool_info[index].blk_cnt = 0; #ifdef SENSOR_RESOLUTION_4MP // 如果是其他分辨率的拼接情况,此处就不用再加了。 mem_cfg.pool_info[index].blk_cnt = 3; #endif #ifdef BINOCULOR_AVS // vsp in,及双目rawall pipe out(depth=1) mem_cfg.pool_info[index].blk_cnt += (3 * vsp_src_cnt); #endif mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; #endif #ifdef BINOCULOR_AVS // vsp out -- 拼接完成的尺寸,vprc、venc mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(ALIGN_CEIL_16(VSP_VPE_OUT_W_0 + VSP_VPE_OUT_W_1 - AVS_OVERLAP_W_0), VDO_SIZE_H, HD_VIDEO_PXLFMT_YUV420); mem_cfg.pool_info[index].blk_cnt = 6; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; // vsp scl out -- 拼接完成后gfx scale的尺寸 mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(ALIGN_CEIL_16(AVS_SCL_OUT_DEF_W), AVS_SCL_OUT_DEF_H, HD_VIDEO_PXLFMT_YUV420); mem_cfg.pool_info[index].blk_cnt = 6; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; // dre fusion buffer for (i = 0; i < vsp_src_cnt; i ++) { if (vsp_ovlp_w[i]) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = 2 * VDO_YUV_BUFSIZE(vsp_ovlp_w[i], AVS_OVERLAP_H, HD_VIDEO_PXLFMT_Y8); mem_cfg.pool_info[index].blk_cnt = vsp_dev_cnt * 6; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; } } // DRE working buffer max_ovlp_width = MAX_VAL(MAX_VAL(MAX_VAL(vsp_ovlp_w[0], vsp_ovlp_w[1]),vsp_ovlp_w[2]),vsp_ovlp_w[3]); mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = MAX_AVS_SRC_CHAN_NUM * ALIGN_CEIL_16(max_ovlp_width) * AVS_OVERLAP_H; mem_cfg.pool_info[index].blk_cnt = vsp_dev_cnt; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; #endif // config common pool (cap) mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_RAW_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H, CAP_OUT_FMT) +VDO_CA_BUF_SIZE(CA_WIN_NUM_W, CA_WIN_NUM_H) +VDO_LA_BUF_SIZE(LA_WIN_NUM_W, LA_WIN_NUM_H); #ifdef AIISP_ENABLED mem_cfg.pool_info[index].blk_cnt = 6; /*todo: 暂定6块,实际需要根据测试情况减少*/ #else mem_cfg.pool_info[index].blk_cnt = 2; #endif mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; /* BNR */ if (g_is_nt98539a) { mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = vendor_common_mem_calc_max_buf_size(VDO_SIZE_W, VDO_SIZE_H, BNR_OUT_FMT); // NOTE: dim need align to 16 for rotate buffer mem_cfg.pool_info[index].blk_cnt = 4; /*todo*/ #ifdef BINOCULOR_AVS mem_cfg.pool_info[index].blk_cnt *= 2; #endif mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = vendor_common_mem_calc_max_buf_size(VDO_SIZE_W, VDO_SIZE_H, BNR_REF_FMT); // NOTE: dim need align to 16 for rotate buffer mem_cfg.pool_info[index].blk_cnt = 3; /*todo*/ #ifdef BINOCULOR_AVS mem_cfg.pool_info[index].blk_cnt *= 2; #endif mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; #ifdef AIISP_ENABLED mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_AIDED_MAP_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H, HD_VIDEO_PXLFMT_RAW12); // NOTE: dim need align to 16 for rotate buffer mem_cfg.pool_info[index].blk_cnt = 2; /*todo*/ mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_AIDED_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H, HD_VIDEO_PXLFMT_RAW12); // NOTE: dim need align to 16 for rotate buffer mem_cfg.pool_info[index].blk_cnt = 3; /*todo*/ mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; #endif } UINT32 md_buf_size = 0; #if 1 // MD #define MD_HEAD_BUFSIZE() (0x40) // Note , the md info w, h is vprc input w, h not out w, h #define MD_INFO_BUFSIZE(w, h) (ALIGN_CEIL_64((((w + 511) >> 9) << 2) * ((h + 15) >> 4))) md_buf_size = MD_HEAD_BUFSIZE() + MD_INFO_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H); #endif // config common pool (main) mem_cfg.pool_info[index].type = HD_COMMON_MEM_COMMON_POOL; mem_cfg.pool_info[index].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(VDO_SIZE_W, VDO_SIZE_H, HD_VIDEO_PXLFMT_YUV420)+md_buf_size; mem_cfg.pool_info[index].blk_cnt = 3; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; #ifdef JPEG_SEPERATE_OSD /*config commom pool osg--peg, jpeg不使用pingpong buffer,所以不单独给时间osd分配两倍内存*/ mem_cfg.pool_info[index].type = HD_COMMON_MEM_OSG_POOL; mem_cfg.pool_info[index].blk_size = get_stampsize(STRM_ID_JPEG,0); mem_cfg.pool_info[index].blk_cnt = 4; mem_cfg.pool_info[index].ddr_id = DDR_ID0; index++; #endif ret = hd_common_mem_init(&mem_cfg); return ret; }
09-29
【电力系统】单机无穷大电力系统短路故障暂态稳定Simulink仿真(带说明文档)内容概要:本文档围绕“单机无穷大电力系统短路故障暂态稳定Simulink仿真”展开,提供了完整的仿真模型与说明文档,重点研究电力系统在发生短路故障后的暂态稳定性问题。通过Simulink搭建单机无穷大系统模型,模拟不同类型的短路故障(如三相短路),分析系统在故障期间及切除后的动态响应,包括发电机转子角度、转速、电压和功率等关键参数的变化,进而评估系统的暂态稳定能力。该仿真有助于理解电力系统稳定性机理,掌握暂态过程分析方法。; 适合人群:电气工程及相关专业的本科生、研究生,以及从事电力系统分析、运行与控制工作的科研人员和工程师。; 使用场景及目标:①学习电力系统暂态稳定的基本概念与分析方法;②掌握利用Simulink进行电力系统建模与仿真的技能;③研究短路故障对系统稳定性的影响及提高稳定性的措施(如故障清除时间优化);④辅助课程设计、毕业设计或科研项目中的系统仿真验证。; 阅读建议:建议结合电力系统稳定性理论知识进行学习,先理解仿真模型各模块的功能与参数设置,再运行仿真并仔细分析输出结果,尝试改变故障类型或系统参数以观察其对稳定性的影响,从而深化对暂态稳定问题的理解。
本研究聚焦于运用MATLAB平台,将支持向量机(SVM)应用于数据预测任务,并引入粒子群优化(PSO)算法对模型的关键参数进行自动调优。该研究属于机器学习领域的典型实践,其核心在于利用SVM构建分类模型,同时借助PSO的全局搜索能力,高效确定SVM的最优超参数配置,从而显著增强模型的整体预测效能。 支持向量机作为一种经典的监督学习方法,其基本原理是通过在高维特征空间中构造一个具有最大间隔的决策边界,以实现对样本数据的分类或回归分析。该算法擅长处理小规模样本集、非线性关系以及高维度特征识别问题,其有效性源于通过核函数将原始数据映射至更高维的空间,使得原本复杂的分类问题变得线性可分。 粒子群优化算法是一种模拟鸟群社会行为的群体智能优化技术。在该算法框架下,每个潜在解被视作一个“粒子”,粒子群在解空间中协同搜索,通过不断迭代更新自身速度与位置,并参考个体历史最优解和群体全局最优解的信息,逐步逼近问题的最优解。在本应用中,PSO被专门用于搜寻SVM中影响模型性能的两个关键参数——正则化参数C与核函数参数γ的最优组合。 项目所提供的实现代码涵盖了从数据加载、预处理(如标准化处理)、基础SVM模型构建到PSO优化流程的完整步骤。优化过程会针对不同的核函数(例如线性核、多项式核及径向基函数核等)进行参数寻优,并系统评估优化前后模型性能的差异。性能对比通常基于准确率、精确率、召回率及F1分数等多项分类指标展开,从而定量验证PSO算法在提升SVM模型分类能力方面的实际效果。 本研究通过一个具体的MATLAB实现案例,旨在演示如何将全局优化算法与机器学习模型相结合,以解决模型参数选择这一关键问题。通过此实践,研究者不仅能够深入理解SVM的工作原理,还能掌握利用智能优化技术提升模型泛化性能的有效方法,这对于机器学习在实际问题中的应用具有重要的参考价值。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值