예제 #1
0
 T pop() {
     if (front->empty()) {
         js::Reverse(back->begin(), back->end());
         Vec *tmp = front;
         front = back;
         back = tmp;
     }
     T item = front->back();
     front->popBack();
     return item;
 }        
예제 #2
0
void Instruction::update_in_a_cycle() {
    ++Instruction::cur_op_id;
    Vec<std::pair<Instruction *,unsigned>> stack;
    stack.emplace_back( this, 0 );
    while ( true ) {
        std::pair<Instruction *,unsigned> t = stack.back();

        // instruction
        if ( t.first->op_id == Instruction::cur_op_id ) {
            stack.pop_back();
            if ( t.first->num_in_dfs_stack >= 0 )
                for( unsigned j = t.first->num_in_dfs_stack; j < stack.size(); ++j )
                    stack[ j ].first->in_a_cycle = true;
        } else {
            t.first->op_id = Instruction::cur_op_id;
            t.first->num_in_dfs_stack = stack.size() - 1;
        }

        // next
        while ( stack.back().second >= stack.back().first->next.size() ) {
            stack.back().first->num_in_dfs_stack = - 1;
            stack.pop_back();
            if ( stack.empty() )
                return;
        }
        stack.emplace_back( stack.back().first->next[ stack.back().second++ ].inst, 0 );
    }
}
예제 #3
0
static void push_not_rec( BoolOpSeq &res, const BoolOpSeq &a, const Vec<int> &ind ) {
    if ( ind.size() == a.or_seq.size() ) {
        Vec<BoolOpSeq::Item> tmp;
        for( int i = 0; i < ind.size(); ++i )
            tmp << BoolOpSeq::Item{ a.or_seq[ i ][ ind[ i ] ].expr, not a.or_seq[ i ][ ind[ i ] ].pos };
        res.or_seq << tmp;
        return;
    }

    Vec<int> tmp = ind; tmp << 0;
    for( int i = 0; i < a.or_seq[ ind.size() ].size(); ++i ) {
        tmp.back() = i;
        push_not_rec( res, a, tmp );
    }
}
예제 #4
0
void strategy2()
{
    int numElems;
    cin >> numElems;
    Vec plants;

    Killers killers; //  toxicity, days to live
    int maxDays(-1);
    //
    // Read in all the plant values
    //
    for (int ii = 0; ii < numElems; ii++)
    {
        plants.push_back(0);
        cin >> plants.back();
    }

    killers.push_front(make_pair(plants[0], -1));

    for (int ii = 1; ii < numElems; ii++)
    {
        int myTTL(1);
        while (!killers.empty())
        {
            //
            // Compare this plant's toxicity to the previous known killer
            //
            int thisTox(plants[ii]);
            int killerTox(killers.front().first);
            cout << "thisTox " << thisTox << " killerTox " << killerTox << endl;

            // If we're stronger than newest killer, remove it from the kill
            // list. Our TTL is the killers TTL + 1
            if (thisTox < killerTox) 
            {
                myTTL = max(killers.front().second + 1, myTTL);
                cout << "myTTL " << myTTL << endl;
                killers.pop_front();
            //    maxDays = max(maxDays, myTTL);
//                cout << "maxDays is now " << maxDays << endl;
            }
            else
            {
                // We will die in 1 day, don't need to run through the
                // rest of the kill list
//                maxDays = max(maxDays, 0);
                break;
            }
            dumpKillers(killers);
        }
        if (killers.empty())
        {
            // The newest plant is stronger than all others,
            // it's the sole occupant of the kill list
            myTTL = -1;
        }
        killers.push_front(make_pair(plants[ii], myTTL));
        maxDays = max(maxDays, myTTL);
        dumpKillers(killers);
        
    }
    maxDays = max(maxDays, 0);
    cout << maxDays << endl;
}
예제 #5
0
파일: ascendvec.cpp 프로젝트: herumi/misc
 void append(uint32_t pos)
 {
     assert(v_.empty() ? pos == 0 : v_.back() < pos);
     v_.push_back(pos);
 }