Ejemplo n.º 1
0
void DP(int a[])
{
	int i, j, k;
	for (i = 1;i <= n;i++)
		sum[i] = sum[i - 1] + a[i];
	for (i = 0;i <= n;i++)
		for (j = 0;j <= m;j++)
		{
			A[i][j] = 0;
			B[i][j] = -1u >> 1;
		}
	for (i = 1;i <= n;i++)
	{
		A[i][1] = B[i][1] = (sum[i] % 10 + 10) % 10;
	}
	A[0][0] = 1;
	B[0][0] = 1;
	for (j = 2;j <= m;j++)
	{
		for (i = j;i <= n;i++)
		{
			for (k = j - 1;k<i;k++)
			{
				{
					A[i][j] = MaxValue(A[i][j], A[k][j - 1] * (((sum[i] - sum[k]) % 10 + 10) % 10));
					B[i][j] = MinValue(B[i][j], B[k][j - 1] * (((sum[i] - sum[k]) % 10 + 10) % 10));
				}
			}
		}
	}
	mx = MaxValue(mx, A[n][m]);
	mn = MinValue(mn, B[n][m]);
}
Ejemplo n.º 2
0
void FTimespan::Assign( int32 Days, int32 Hours, int32 Minutes, int32 Seconds, int32 Milliseconds )
{
	int64 totalms = 1000 * (60 * 60 * 24 * (int64)Days + 60 * 60 * (int64)Hours + 60 * (int64)Minutes + (int64)Seconds) + (int64)Milliseconds;
	check((totalms >= MinValue().GetTotalMilliseconds()) && (totalms <= MaxValue().GetTotalMilliseconds()));

	Ticks = totalms * ETimespan::TicksPerMillisecond;
}
Ejemplo n.º 3
0
Board* MinimaxDecision(Board* board, int turn, clock_t st){
    BoardQueue *q;
    q = board->successor(turn);
    cout << endl;
    
    Board* tmpboard = NULL;
    int tmpvalue = -99999;
    int min;
    
    while(!q->isEmpty()){
        Board* b = q->dequeue();
        min = MinValue(b, changeTurn(turn),st);
        if(min > tmpvalue){
            tmpvalue = min;
            if(tmpboard != NULL){
                Board* tmmp = tmpboard;
                tmpboard = b;
                delete tmmp;
            }else{
                tmpboard = b;
            }
        }else{
            delete b;/////// Burayı control et hacıııı
        }
    }
    tmpboard->resetLevel();
    cout << "Min : " << tmpvalue << endl;
    return tmpboard;
}
Ejemplo n.º 4
0
/************************************************
函数功能:获取第index个丑数
参数1:要获取的第几个
返回值:第index个丑数
说明: 详细说明见比价《算法——找第1500个丑数》
头文件:<stdlib.h>
作者: Lee.C
完成时间:2016-08-19
**************************************************/
int GetUglyNumber(int index)
{
    if(index <= 0)
        return 0;

    int retUglyNumber = 0;
    int minUglyNumber = 0;
    int *pUglyArrays = (int*)malloc(index*sizeof(int));
    pUglyArrays[0] = 1;
    int nextUglyIndex = 1;

    int *pMultiply2 = pUglyArrays;
    int *pMultiply3 = pUglyArrays;
    int *pMultiply5 = pUglyArrays;

    while(nextUglyIndex < index)
    {
        minUglyNumber = MinValue(*pMultiply2 * 2, *pMultiply3 * 3, *pMultiply5 * 5);
        pUglyArrays[nextUglyIndex] = minUglyNumber;

        //更新位置
        while(*pMultiply2 * 2 <= pUglyArrays[nextUglyIndex])
            ++pMultiply2;
        while(*pMultiply3 * 3 <= pUglyArrays[nextUglyIndex])
            ++pMultiply3;
        while(*pMultiply5 * 5 <= pUglyArrays[nextUglyIndex])
            ++pMultiply5;

        ++nextUglyIndex;
    }

    retUglyNumber = pUglyArrays[index-1];
    free(pUglyArrays);
    return retUglyNumber;
}
Ejemplo n.º 5
0
sf::IntRect Collision::GetAABB(const sf::Sprite& Object) {

    //Get the top left corner of the sprite regardless of the sprite's center
    //This is in Global Coordinates so we can put the rectangle back into the right place
    sf::Vector2f pos = Object.TransformToGlobal(sf::Vector2f(0, 0));

    //Store the size so we can calculate the other corners
    sf::Vector2f size = Object.GetSize();

    float Angle = Object.GetRotation();

    //Bail out early if the sprite isn't rotated
    if (Angle == 0.0f) {
        return sf::IntRect(static_cast<int> (pos.x),
                static_cast<int> (pos.y),
                static_cast<int> (pos.x + size.x),
                static_cast<int> (pos.y + size.y));
    }

    //Calculate the other points as vectors from (0,0)
    //Imagine sf::Vector2f A(0,0); but its not necessary
    //as rotation is around this point.
    sf::Vector2f B(size.x, 0);
    sf::Vector2f C(size.x, size.y);
    sf::Vector2f D(0, size.y);

    //Rotate the points to match the sprite rotation
    B = RotatePoint(B, Angle);
    C = RotatePoint(C, Angle);
    D = RotatePoint(D, Angle);

    //Round off to int and set the four corners of our Rect
    int Left = static_cast<int> (MinValue(0.0f, B.x, C.x, D.x));
    int Top = static_cast<int> (MinValue(0.0f, B.y, C.y, D.y));
    int Right = static_cast<int> (MaxValue(0.0f, B.x, C.x, D.x));
    int Bottom = static_cast<int> (MaxValue(0.0f, B.y, C.y, D.y));

    //Create a Rect from out points and move it back to the correct position on the screen
    sf::IntRect AABB = sf::IntRect(Left, Top, Right, Bottom);
    AABB.Offset(static_cast<int> (pos.x), static_cast<int> (pos.y));
    return AABB;
}
Ejemplo n.º 6
0
bool NWChar::TryParse(const Text &t, wchar_t &c)
{
	char cadena[1001];
	((Text *)&t)->GetAnsiString(cadena, 1000);
	errno = 0;
	long long ll = atoll(cadena);
	if (errno != 0) return false;
	if (ll < MinValue() || ll > MaxValue()) return false;
	c = ll;
	return true;
}
Ejemplo n.º 7
0
int main() {
  MinHeap* heap = NewMinHeap();
  for (int i = 10; i > 0; --i) {
    Push(heap, i);
    printf("Min Value: %d\n", MinValue(heap));
  }
  while (heap->size > 0) {
    int min = RemoveMin(heap);
    printf("Removed min value: %d.  Size is now %d.", min, heap->size);
  }
}
Ejemplo n.º 8
0
bool NUInt::TryParse(const Text &text, unsigned int &n)
{
	char tt[1001];
	((Text *)&text)->GetAnsiString(tt, 1000);
	
	errno = 0;
	long long ll = atoll(tt);
	if (errno != 0) return false;
	if (ll > MaxValue() || ll < MinValue()) return false;
	n = ll;
	return true;
}
Ejemplo n.º 9
0
int MaxValue(Board* state, int turn, clock_t st){
    int alpha = -99999;
    if(CutOffTest(state, st)){
        return state->getValue();
    }
    
    BoardQueue *q;
    q = state->successor(turn);
    //    cout << endl;
    
    while(!q->isEmpty()){
        Board* s = q->dequeue();
        alpha = Max(alpha, MinValue(s,changeTurn(turn), st));
        delete s;
    }
    delete q;
    return alpha;
}
Ejemplo n.º 10
0
int main(){

	node* root = NULL;
	Insert(root, 4);
	Insert(root, 2);
	Insert(root, 6);
	Insert(root, 1);
	Insert(root, 3);

	PrintPaths(root);
	std::cout << std::endl;
	int x = Size(root);
		std::cout << x <<" ---" << std::endl;
	int y = MaxDepth(root);	
	std::cout << "depth= " << y << std::endl;

	int min = MinValue(root);
	std::cout << "min= " << min << std::endl;

	if(HasPathSum(root,10))
		std::cout <<"yessss"<< std::endl;
return 0;
}
Ejemplo n.º 11
0
FTimespan FTimespan::FromSeconds( double Seconds )
{
	check((Seconds >= MinValue().GetTotalSeconds()) && (Seconds <= MaxValue().GetTotalSeconds()));

	return FTimespan(Seconds * ETimespan::TicksPerSecond);
}
Ejemplo n.º 12
0
FTimespan FTimespan::FromMinutes( double Minutes )
{
	check((Minutes >= MinValue().GetTotalMinutes()) && (Minutes <= MaxValue().GetTotalMinutes()));

	return FTimespan(Minutes * ETimespan::TicksPerMinute);
}
Ejemplo n.º 13
0
FTimespan FTimespan::FromMilliseconds( double Milliseconds )
{
	check((Milliseconds >= MinValue().GetTotalMilliseconds()) && (Milliseconds <= MaxValue().GetTotalMilliseconds()));

	return FTimespan(Milliseconds * ETimespan::TicksPerMillisecond);
}
Ejemplo n.º 14
0
void CalcAng(float4 coor0,float4 coor1,float4 coor2,float4 coor3 , double* dangle, double *cangle, double *vol,double* mxdangle)
{
	double   x21,y21,z21, x31,y31,z31, x41,y41,z41, x32,y32,z32, x42,y42,z42, x43,y43,z43  ,
		x123,y123,z123,o123, x124,y124,z124,o124, x134,y134,z134,o134, x234,y234,z234,o234,
		o21,o31,o41,o32,o42,o43;
	double d[6];
	double c[12];
	x21  = coor1.x - coor0.x;
	y21  = coor1.y - coor0.y;
	z21  = coor1.z - coor0.z;

	x31  = coor2.x - coor0.x;
	y31  = coor2.y - coor0.y;
	z31  = coor2.z - coor0.z;

	x41  = coor3.x - coor0.x;
	y41  = coor3.y - coor0.y;
	z41  = coor3.z - coor0.z;

	x32  = coor2.x - coor1.x;
	y32  = coor2.y - coor1.y;
	z32  = coor2.z - coor1.z;

	x42  = coor3.x - coor1.x;
	y42  = coor3.y - coor1.y;
	z42  = coor3.z - coor1.z;

	x43  = coor3.x - coor2.x;
	y43  = coor3.y - coor2.y;
	z43  = coor3.z - coor2.z;

	x123 = y21*z31 - z21*y31;
	y123 = z21*x31 - x21*z31;
	z123 = x21*y31 - y21*x31;
	o123 = sqrt(x123*x123 + y123*y123 + z123*z123);

	x124 = y41*z21 - z41*y21; 
	y124 = z41*x21 - x41*z21;
	z124 = x41*y21 - y41*x21;
	o124 = sqrt(x124*x124 + y124*y124 + z124*z124);

	x134 = y31*z41 - z31*y41;
	y134 = z31*x41 - x31*z41;
	z134 = x31*y41 - y31*x41;
	o134 = sqrt(x134*x134 + y134*y134 + z134*z134);

	x234 = y42*z32 - z42*y32;
	y234 = z42*x32 - x42*z32;
	z234 = x42*y32 - y42*x32;
	o234 = sqrt(x234*x234 + y234*y234 + z234*z234);

	d[0] = (x123*x124 + y123*y124 + z123*z124)/(o123*o124);
	d[1] = (x123*x134 + y123*y134 + z123*z134)/(o123*o134);
	d[2] = (x134*x124 + y134*y124 + z134*z124)/(o134*o124);
	d[3] = (x123*x234 + y123*y234 + z123*z234)/(o123*o234);
	d[4] = (x124*x234 + y124*y234 + z124*z234)/(o124*o234);
	d[5] = (x134*x234 + y134*y234 + z134*z234)/(o134*o234);
	if (d[0] < -1.0)  d[0] = -1.0;
	if (d[0] >  1.0)  d[0] =  1.0;
	if (d[1] < -1.0)  d[1] = -1.0;
	if (d[1] >  1.0)  d[1] =  1.0;
	if (d[2] < -1.0)  d[2] = -1.0;
	if (d[2] >  1.0)  d[2] =  1.0;
	if (d[3] < -1.0)  d[3] = -1.0;
	if (d[3] >  1.0)  d[3] =  1.0;
	if (d[4] < -1.0)  d[4] = -1.0;
	if (d[4] >  1.0)  d[4] =  1.0;
	if (d[5] < -1.0)  d[5] = -1.0;
	if (d[5] >  1.0)  d[5] =  1.0;

	d[0] = (PI-acos(d[0])) * 180 / PI;
	d[1] = (PI-acos(d[1])) * 180 / PI;
	d[2] = (PI-acos(d[2])) * 180 / PI;
	d[3] = (PI-acos(d[3])) * 180 / PI;
	d[4] = (PI-acos(d[4])) * 180 / PI;
	d[5] = (PI-acos(d[5])) * 180 / PI;

	o21 = sqrt(x21*x21 + y21*y21 + z21*z21);
	o31 = sqrt(x31*x31 + y31*y31 + z31*z31);
	o41 = sqrt(x41*x41 + y41*y41 + z41*z41);
	o32 = sqrt(x32*x32 + y32*y32 + z32*z32);
	o42 = sqrt(x42*x42 + y42*y42 + z42*z42);
	o43 = sqrt(x43*x43 + y43*y43 + z43*z43);
	c[0] = (x21*x31+y21*y31+z21*z31) / (o21*o31);
	c[1] =-(x21*x32+y21*y32+z21*z32) / (o21*o32);
	c[3] = (x21*x41+y21*y41+z21*z41) / (o21*o41);
	c[4] =-(x21*x42+y21*y42+z21*z42) / (o21*o42);
	c[6] = (x32*x42+y32*y42+z32*z42) / (o32*o42);
	c[7] =-(x32*x43+y32*y43+z32*z43) / (o32*o43);
	c[9] = (x31*x41+y31*y41+z31*z41) / (o31*o41);
	c[10]=-(x31*x43+y31*y43+z31*z43) / (o31*o43);
	if (c[0] < -1.0)  c[0] = -1.0;
	if (c[0] >  1.0)  c[0] =  1.0;
	if (c[1] < -1.0)  c[1] = -1.0;
	if (c[1] >  1.0)  c[1] =  1.0;
	if (c[3] < -1.0)  c[3] = -1.0;
	if (c[3] >  1.0)  c[3] =  1.0;
	if (c[4] < -1.0)  c[4] = -1.0;
	if (c[4] >  1.0)  c[4] =  1.0;
	if (c[6] < -1.0)  c[6] = -1.0;
	if (c[6] >  1.0)  c[6] =  1.0;
	if (c[7] < -1.0)  c[7] = -1.0;
	if (c[7] >  1.0)  c[7] =  1.0;
	if (c[9] < -1.0)  c[9] = -1.0;
	if (c[9] >  1.0)  c[9] =  1.0;
	if (c[10]< -1.0)  c[10]= -1.0;
	if (c[10]>  1.0)  c[10]=  1.0;

	c[0] = acos(c[0]);
	c[1] = acos(c[1]);
	c[2] = PI - c[0] - c[1];
	c[3] = acos(c[3]);
	c[4] = acos(c[4]);
	c[5] = PI - c[3] - c[4];
	c[6] = acos(c[6]);
	c[7] = acos(c[7]);
	c[8] = PI - c[6] - c[7];
	c[9] = acos(c[9]);
	c[10]= acos(c[10]);
	c[11]= PI - c[9] - c[10];

	c[0]  = c[0] * 180 / PI;
	c[1]  = c[1] * 180 / PI;
	c[2]  = c[2] * 180 / PI;
	c[3]  = c[3] * 180 / PI;
	c[4]  = c[4] * 180 / PI;
	c[5]  = c[5] * 180 / PI;
	c[6]  = c[6] * 180 / PI;
	c[7]  = c[7] * 180 / PI;
	c[8]  = c[8] * 180 / PI;
	c[9]  = c[9] * 180 / PI;
	c[10] = c[10]* 180 / PI;
	c[11] = c[11]* 180 / PI;

	*dangle = MinValue(d,6);
	*mxdangle = MaxValue(d,6);
	*cangle = MinValue(c,12);
	*vol = (x123*x41 + y123*y41 + z123*z41) / 6;

};
Ejemplo n.º 15
0
	inline bool IsMuted() const noexcept
	{
		return Get() == MinValue();
	}
Ejemplo n.º 16
0
FTimespan FTimespan::FromDays( double Days )
{
	check((Days >= MinValue().GetTotalDays()) && (Days <= MaxValue().GetTotalDays()));

	return FTimespan(Days * ETimespan::TicksPerDay);
}
Ejemplo n.º 17
0
FTimespan FTimespan::FromHours( double Hours )
{
	check((Hours >= MinValue().GetTotalHours()) && (Hours <= MaxValue().GetTotalHours()));

	return FTimespan(Hours * ETimespan::TicksPerHour);
}
Ejemplo n.º 18
0
	inline void Set(float value) noexcept
	{
		float volume = std::min(std::max(MinValue(), value), MaxValue());
		FMODCHECK(m_pVCA->setVolume(value));
	}