Пример #1
0
//-------------------------------------------------------------------------------
Table::Ptr solveOptimalMinMax(aq::verb::VerbNode::Ptr spTree, 
                              Base& BaseDesc, 
                              Settings& Settings )
{
	if( !spTree->getLeftChild() )
  {
    return NULL;
		// throw generic_error(generic_error::INVALID_QUERY, "");
  }
	aq::verb::VerbNode::Ptr verb1 = spTree->getLeftChild();
  aq::verb::VerbNode::Ptr verb2 = NULL;
	if( !verb1 ) 
    return NULL;
  if ((verb1->getVerbType() == K_MIN) || (verb1->getVerbType() == K_MAX))
    verb2 = verb1->getLeftChild();
  else if ((verb1->getVerbType() == K_AS) && ((verb1->getLeftChild()->getVerbType() == K_MIN) || (verb1->getLeftChild()->getVerbType() == K_MAX)))
    verb2 = verb1->getLeftChild()->getLeftChild();
  else
    return NULL;

	if( verb2->getVerbType() != K_PERIOD )
		return NULL;
	if( spTree->getBrother() == NULL )
		return NULL;
	aq::verb::VerbNode::Ptr spNode = spTree;
	do
	{
		if( spNode->getVerbType() == K_WHERE )
			return NULL;
		spNode = spNode->getBrother();
	} while( spNode->getBrother() );

	aq::verb::ColumnVerb::Ptr columnVerb = boost::dynamic_pointer_cast<aq::verb::ColumnVerb>( verb2 );
	Table::Ptr table = BaseDesc.getTable( columnVerb->getTableName() );
	size_t colIdx = table->getColumnIdx( columnVerb->getColumnOnlyName() );
	Column::Ptr column = table->Columns[colIdx];
	ColumnItem::Ptr minMax = NULL;
	bool min = verb1->getVerbType() == K_MIN;
	for( int partIdx = 0; ; ++partIdx )
	{
		ColumnItem::Ptr item = getMinMaxFromThesaurus( table->ID, colIdx, partIdx, min, BaseDesc, Settings );
		if( !item )
			break;
		if( !minMax )
			minMax = item;
		else
			if( min == ColumnItem::lessThan(item.get(), minMax.get(), column->Type) )
				minMax = item;
	}
	
	table.reset(new Table());
	Column::Ptr newColumn(new Column(*column));
	newColumn->Items.push_back( minMax );
	table->Columns.push_back( newColumn );
	table->TotalCount = 1;
	return table;
}
Пример #2
0
void DFS(TreeNode* root, int sum, Result* res, Route* route) {
    if (sum == root->val) {
        if (!root->left && !root->right) {
            addRoute(route, root->val);
            newColumn(res, route);
            route->size -= 1;
        } else {
            addRoute(route, root->val);
            if (root->left) DFS(root->left, sum - root->val, res, route);
            if (root->right) DFS(root->right, sum - root->val, res, route);
            route->size -= 1;
        }
    } else {
        addRoute(route, root->val);
        if (root->left) DFS(root->left, sum - root->val, res, route);
        if (root->right) DFS(root->right, sum - root->val, res, route);
        route->size -= 1;
    }
}
Пример #3
0
void gameStart(int mode)
{

    bool success;//是否下落成功;若失败,则说明沉底
    int i, j, k, t = 0;
    int cmd = 0;
    int timeLeft[TOTAL_PLAYER+1] = {0, 1000, 1000};
    Block tpBlk[TOTAL_PLAYER+1];

    gameInit();//初始化游戏

    while(1)
    {

        for(i = 1; i <= TOTAL_PLAYER; i++)
        {
            t++;//计时器增加
            setorigin(0, 0); //设置原点
            recoverBk(0, g_player[i].preview.y + 4 * BLOCK_SIZE, 160, 30);
            recoverBk(0, 480 - 30, 160, 30); //重绘预览区
            printScore(t);//显示得分
            drawStageLine();//绘制边界线
            FlushBatchDraw();//执行绘图


            if(g_player[i].dropped == true)
            {

                saveState(i, g_player[i].nowBlk);//保存方块的存在状态


                if(mode == CLEAR && g_player[1+(i==1)].score >= 100)gameOver(i);
                if(reachTop(i))
                {
                    gameOver(i);
                    continue;
                }//判断游戏结束

                k = fullColumn(i);
                if(k > 0)
                {
                    g_player[i].score += k * k;
                    if(mode == NORMAL && g_player[i].score % 10 == 0)newColumn(1 + (i == 1));
                }//计分与消行

                tpBlk[i] = g_player[i].preBlk; //备份预览方块
                g_player[i].nowBlk = preToNow(g_player[i].preBlk);//previewBlock变为player[1].nowBlk
                g_player[i].preBlk = createBlk(); //产生新的预览方块
                refreshBlk(i, tpBlk[i], g_player[i].preBlk, PREVIEW); //绘制新的previewBlock

                g_player[i].dropped = false;


            }


            getCmd(&cmd);//获得命令
            timeLeft[i] -= 10;
            for  (j = 1; j <= TOTAL_PLAYER; j++)
            {

                tpBlk[j] = g_player[j].nowBlk;

                success = DispatchCommand(j, cmd);
                if(success)refreshBlk(j, tpBlk[j], g_player[j].nowBlk);
                else continue;

            }//在一个玩家的循环中要同时处理两个玩家

            if(timeLeft[i] <= 0)
            {
                if(mode == NORMAL)timeLeft[i] = INIT_DELAY - (int)(2.5 * g_player[1+(i==1)].score);
                else timeLeft[i] = (int)(INIT_DELAY - (t / 1000.0)); //速度规则
                if(timeLeft[i] < MIN_DELAY)timeLeft[i] = 3 * MIN_DELAY;

                tpBlk[i] = g_player[i].nowBlk;
                if(i == 1)
                    success = DispatchCommand(1, CMD_DOWN);
                else
                    success = DispatchCommand(2, CMD_DOWN2);
                if(success)refreshBlk(i, tpBlk[i], g_player[i].nowBlk);

            }

        }


    }
    getch();
    closegraph();
}