コード例 #1
0
ファイル: select_kth.c プロジェクト: QMonkey/ACM-ICPC
int32_t* select_kth(int32_t *begin,int32_t *end,int32_t kth,int (*comparator)(int32_t,int32_t))
{
	int32_t *pivot = partition(begin,end,comparator);
	int32_t nth = pivot - begin + 1;
	int32_t *result = NULL;
	if(nth == kth)
	{
		result = pivot;
	}
	else if(nth > kth)
	{
		result = select_kth(begin,pivot,kth,comparator);
	}
	else
	{
		result = select_kth(pivot + 1,end,kth - nth,comparator);
	}
	return result;
}
コード例 #2
0
ファイル: vbrquantize.c プロジェクト: TravisKraatz/cinelerra
static  FLOAT8
calc_sfb_noise_mq(const FLOAT8 * xr, const FLOAT8 * xr34, int bw, int sf, int mq, FLOAT8 * scratch)
{
    int     j, k;
    fi_union fi;
    FLOAT8  temp;
    FLOAT8 xfsfm = 0.0, xfsf = 0.0;
    FLOAT8 const sfpow   =  POW20(sf); /*pow(2.0,sf/4.0); */
    FLOAT8 const sfpow34 = IPOW20(sf); /*pow(sfpow,-3.0/4.0); */

    for (j = 0; j < bw; ++j) {
        temp = xr34[j] * sfpow34;
        if (temp > IXMAX_VAL)
            return -1;

#ifdef TAKEHIRO_IEEE754_HACK
        temp += MAGIC_FLOAT;
        fi.f = temp;
        fi.f = temp + (adj43asm - MAGIC_INT)[fi.i];
        fi.i -= MAGIC_INT;
#else
        XRPOW_FTOI(temp, fi.i);
        XRPOW_FTOI(temp + QUANTFAC(fi.i), fi.i);
#endif

        temp = fabs(xr[j]) - pow43[fi.i] * sfpow;
        temp *= temp;

        scratch[j] = temp;
        if (xfsfm < temp)
            xfsfm = temp;
        xfsf += temp;
    }
    if (mq == 1)
        return bw * select_kth(scratch, bw, bw * 13 / 16);

    xfsf /= bw;
    for (k = 1, j = 0; j < bw; ++j) {
        if (scratch[j] > xfsf) {
            xfsfm += scratch[j];
            ++k;
        }
    }
    return xfsfm / k * bw;
}