Esempio n. 1
0
File: 710.cpp Progetto: Shmuma/cc
int solve (int x1, int y1, int x2, int y2)
{
    t_x = x2;
    t_y = y2;
    best = 10000000;

    if (x2-1 == x1 && y2 == y1)
        best = 1;
    if (x2 == x1 && y2-1 == y1)
        best = 1;
    if (x2+1 == x1 && y2 == y1)
        best = 1;
    if (x2 == x1 && y2+1 == y1)
        best = 1;

    memset (sol, 0, sizeof (sol));

    if (x1 > 0 && !field[x1-1][y1])
        do_solve (x1-1, y1, 1, 1);
    if (y1 > 0 && !field[x1][y1-1])
        do_solve (x1, y1-1, 1, 2);
    if (x1 <= w && !field[x1+1][y1])
        do_solve (x1+1, y1, 1, 3);
    if (y1 <= h && !field[x1][y1+1])
        do_solve (x1, y1+1, 1, 4);

    return best == 10000000 ? 0 : best;
}
Esempio n. 2
0
//读变量的值
Type getvalue(LTree idTree)
{
	Type ans;
	int offset;

	switch(idTree->type)
	{
	case INT:
		ans.intval=*(int *)(idheap+idTree->val.intval); break;
	case TBOOL:
		ans.boolval=*(bool *)(idheap+idTree->val.intval); break;
	case TDOUBLE:
		ans.doubleval=*(double *)(idheap+idTree->val.intval); break;
	case ARRAY:
		offset=do_solve(idTree->chi).intval;
		switch(idTree->type2)
		{
		case INT:
			ans.intval=*(*((int **)(idheap+idTree->val.intval))+offset); break;
		case TBOOL:
			ans.boolval=*(*((bool **)(idheap+idTree->val.intval))+offset); break;
		case TDOUBLE:
			ans.doubleval=*(*((double **)(idheap+idTree->val.intval))+offset); break;
		}
		break;
	}
	return ans;
}
Esempio n. 3
0
//对变量赋值
void putvalue(LTree idTree, Type value)
{
	int offset;
	switch(idTree->type)
	{
	case INT:
		*(int *)(idheap+idTree->val.intval)=value.intval; break;
	case TBOOL:
		*(bool *)(idheap+idTree->val.intval)=value.boolval; break;
	case TDOUBLE:
		*(double *)(idheap+idTree->val.intval)=value.doubleval; break;
	case ARRAY:
		offset=do_solve(idTree->chi).intval;
		switch(idTree->type2)
		{
		case INT:
			*(*((int **)(idheap+idTree->val.intval))+offset)=value.intval; break;
		case TBOOL:
			*(*((bool **)(idheap+idTree->val.intval))+offset)=value.boolval; break;
		case TDOUBLE:
			*(*((double **)(idheap+idTree->val.intval))+offset)=value.doubleval; break;
		}
		break;
	}
}
Esempio n. 4
0
/*将print中的bro参数链转化为字节数组,存储在*args中,
返回总参数大小(单位:字节, 规约为4的倍数(push一次压栈4字节))*/
static int buildArgs(LTree bro, char **args)
{
	int size=0;		//存储所有参数所需要的空间大小(字节)
	int pos=0;		//参数的位置(字节)
	char *ans;
	LTree t;
	Type re;		//临时存储参数树执行结果

	for(t=bro;t;t=t->bro)
		switch(t->returnType)
		{
		case INT: case TBOOL:
			size+=sizeof(int); break;
		case TDOUBLE:
			size+=sizeof(double); break;
		}
	ans=(char *)malloc(size);
	for(t=bro;t;t=t->bro)
		switch(t->returnType)
		{
		case INT:
			re=do_solve(t);
			*(int *)(ans+pos)=re.intval; 
			pos+=4;
			break;
		case TBOOL:
			re=do_solve(t);
			*(char **)(ans+pos)=re.boolval==false ? "false" : "true";
			pos+=4;
			break;
		case TDOUBLE:
			re=do_solve(t);
			*(double *)(ans+pos)=re.doubleval;
			pos+=sizeof(double);
			break;
		}
	*args=ans;

	return size;
}
Esempio n. 5
0
File: 710.cpp Progetto: Shmuma/cc
void do_solve (int x, int y, int lev, int dir)
{
    //    printf ("%d %d\n", x, y);
    
//     if (lev > w || lev > h || lev > best)
//         return;

    //    print ();

    if (x == t_x && y == t_y)
        if (best > lev)
            best = lev;

    if (field[x][y] || sol[x][y])
        return;

    sol[x][y] = 1;

    // trying to estimate direction to target
    if (x - t_x > 0) {
        if (x > 0 && dir != 3)
            do_solve (x-1, y, lev + lev_add (dir, 1), 1);
        if (x <= w && dir != 1)
            do_solve (x+1, y, lev + lev_add (dir, 3), 3);
    }
    else {
        if (x <= w && dir != 1)
            do_solve (x+1, y, lev + lev_add (dir, 3), 3);
        if (x > 0 && dir != 3)
            do_solve (x-1, y, lev + lev_add (dir, 1), 1);
    }

    if (y - t_y > 0) {
        if (y > 0 && dir != 4)
            do_solve (x, y-1, lev + lev_add (dir, 2), 2);
        if (y <= h && dir != 2)
            do_solve (x, y+1, lev + lev_add (dir, 4), 4);
    }
    else {
        if (y <= h && dir != 2)
            do_solve (x, y+1, lev + lev_add (dir, 4), 4);
        if (y > 0 && dir != 4)
            do_solve (x, y-1, lev + lev_add (dir, 2), 2);
    }

    sol[x][y] = 0;
}
Esempio n. 6
0
void arrayNewSize(LTree node)
{
	LTree array;
	void **p;
	int size;

	array=node->chi;
	size=do_solve(array->bro).intval;
	switch(array->type2)
	{
	case INT: case TBOOL:
		size*=sizeof(int); break;
	case TDOUBLE:
		size*=sizeof(double); break;
	}

	p=(void**)(idheap+array->val.intval);
	if(*p) free(*p);
	*p=malloc(size);
}
			void solve(data_center_type const& dc,
					   real_type wp,
					   real_type wm,
					   real_type ws,
					   UtilFwdIterT vm_util_first,
					   UtilFwdIterT vm_util_last,
					   ShareFwdIterT vm_share_first,
					   ShareFwdIterT vm_share_last)
	{
		virtual_machine_utilization_map vm_util_map(vm_util_first, vm_util_last);

		virtual_machine_share_map vm_share_map;
		while (vm_share_first != vm_share_last)
		{
			vm_share_map[vm_share_first->first] = resource_share_container(vm_share_first->second.begin(),
																		   vm_share_first->second.end());
			++vm_share_first;
		}

		do_solve(dc, wp, wm, ws, vm_util_map, vm_share_map);
	}