Ejemplo n.º 1
0
 int trap(int A[], int n) {
     if (n <= 2) return 0;
     GenIncPos(A, n);
     int pos1 = IncPos[IncPos.size()-1];
     int ans = GetAns(A, n , IncPos);
     //cout <<"pos: "<< pos1 << " ans "<< ans << endl;
     reverse(A, A+n);
     GenIncPos(A, n);
     int pos2 = IncPos[IncPos.size()-1];
     ans += GetAns(A, n, IncPos);
     
     //cout <<"pos: "<< pos2 << " ans "<< ans << endl;
     pos1 = n - pos1 - 1;
     ans += GetWater(pos2, pos1, A);
     
     //cout <<"pos: "<< pos1 << " ans "<< ans << endl;
     return ans;
 }
Ejemplo n.º 2
0
int main()
{
     int kcase;
     scanf( "%d", &kcase );
     while( kcase-- )
     {
         scanf( "%s %s", s, t );
         GetAns();
     } 
     return 0;
}
bool Solve(std::istream& ist, std::ostream& ost, const bool multipleTestMode)
{
    StopWatch<1> sw; sw;

    // 
    size_t n, m, k;
    size_t w;
    ist >> n >> m >> k >> w;

    if (multipleTestMode && !ist)
        return false;

    vector_2d_string8_t levels(k, vector_string8_t(n));

    for (size_t l = 0; l < k; l++)
    {
        for (size_t i = 0; i < n; i++)
        {
            ist >> levels[l][i];
        }
    }

    // 
    vector_2d_size_t diff(k, vector_size_t(k));
    for (size_t a1 = 0; a1 < k; a1++)
    {
        for (size_t a2 = a1 + 1; a2 < k; a2++)
        {
            for (size_t i = 0; i < n; i++)
            {
                for (size_t j = 0; j < m; j++)
                {
                    if (levels[a1][i][j] != levels[a2][i][j])
                    {
                        diff[a1][a2] += 1;
                        diff[a2][a1] += 1;
                    }
                }
            }
        }
    }

    size_t minDiff = 1UL << 31;
    size_t minA1 = 0;
    size_t minA2 = 0;
    for (size_t a1 = 0; a1 < k; a1++)
    {
        for (size_t a2 = a1 + 1; a2 < k; a2++)
        {
            const size_t d = diff[a1][a2];
            if (minDiff > d)
            {
                minDiff = d;
                minA1 = a1;
                minA2 = a2;
            }
        }
    }
    const size_t fieldSize = n * m;
    LOCAL_ASSERT(minA1 != minA2);

    vector_move_t minSequence;
    const size_t ans = GetAns(fieldSize, w, diff, minA1, minSequence);

    ost << ans << std::endl;
    for (size_t i = 0; i < k; i++)
    {
        ost << (minSequence[i].index + 1) << ' ' << minSequence[i].way << std::endl;
    }
    
    return multipleTestMode;
}