数据挖掘(Data Mining, uva1591)

  1. 本题主要在于理解题意,Q数组可以不连续存储指的是只要公式能够满足即可, 不一定有规律的存储。比如,先11个byte存储数据,1个byte空闲,再12个byte存储数据, 1个byte空闲。简单计算可以得出K >= Sq * N为充要条件
  2. 测试数据Northeastern Europe (NEERC)2003
// uva1591.cpp
#include 
#include 
#define MAXN 31 

int main(){
    long long N;
    int Sp, Sq; //
    while(scanf("%d%d%d", &N, &Sp, &Sq) == 3){
        bool first = true;
        long long K;
        int minA = 0, minB = 0;
        for (int A = 0; A <= MAXN; A++){     // A, B at least 31
            for (int B = 0; B <= MAXN; B++){
                long long temp = 0;
                temp = (( (N - 1) * Sp + ( ((N - 1) * Sp ) << A) ) >> B) + Sq;  
                if (temp < Sq * N) break;  // why?
                if (first) { K = temp; minA = A; minB = B; first = false; }
                else if(K > temp){
                    K = temp;
                    minA = A;
                    minB = B;
                }
            }
        }
        printf("%lld %d %d\n", K, minA, minB);
    }
    return 0;
}

你可能感兴趣的:(成长日志,数据挖掘,uva)