Ejemplo n.º 1
0
int main()
{
    int T;
    POINT A, B, C, D, N, Nd;
    int P, Q, R;
    double beginAB;
    double endAB;
    double midmidAB;
    double midAB;
    double t1;
    double t2;
    double min;

    scanf("%d", &T);
    while(T--)
    {
        scanf("%lf %lf %lf %lf", &A.x, &A.y, &B.x, &B.y);
        scanf("%lf %lf %lf %lf", &C.x, &C.y, &D.x, &D.y);
        scanf("%d %d %d", &P, &Q, &R);

        beginAB = 0;
        endAB = 1;
        midAB = (beginAB + endAB) / 2;
        midmidAB = (midAB + endAB) / 2;

        while(endAB - beginAB > 1e-6)
        {

            N = createP(A, B, midAB);
            Nd = createP(A, B, midmidAB);

            t1 = distanceTime(A, N, P) + otherTime(N, C, D, R, Q);
            t2 = distanceTime(A, Nd, P) + otherTime(Nd, C, D, R, Q);
            if(t1 > t2)
            {
                beginAB = midAB;
                midAB = (beginAB + endAB) / 2;
                midmidAB = (midAB + endAB) / 2;
                min = t2;
            }
            else
            {
                endAB = midmidAB;
                midAB = (beginAB + endAB) / 2;
                midmidAB = (midAB + endAB) / 2;
                min = t1;
            }
        }
        printf("%.2lf\n", min);
    }
    return 0;
}
Ejemplo n.º 2
0
/* Computes de LCS and prints its length and value to the output */
void lcs( char *stringA, char *stringB, int m, int n ){
	int **mat = (int **) malloc(sizeof(int *)* (m + 1));
	int **p = (int**) malloc(sizeof(int *)*27);
	int i=0;
	char *c = (char *) malloc(sizeof(char)*27);
	c[0] = ' ';	
	for(i=1;i<=26;i++){
		c[i]=(char)'A'+i-1;
	}
	for(i = 0; i <= m; i++) {
		mat[i] = (int *) malloc(sizeof(int)* (n + 1));		
		mat[i][0] = 0;
	}

	for(i = 0; i <= n; i++) 
		mat[0][i] = 0;

	for (i = 0; i <= 26; i++) 
		p[i] = (int *) malloc(sizeof(int)*(n + 1));
	
	createP(p,c,stringB,n);
	fillMatrixWithValues(mat,p,stringA,stringB,m,n);
   	computeLCSResult(mat,stringA,stringB,m,n);

	for(i = 0; i <= m; i++)
		free(mat[i]);
	
	free(mat);

	for(i = 0; i <= 4; i++)	
		free(p[i]);

	free(p);
	free(c);	
}
Ejemplo n.º 3
0
double otherTime(POINT N, POINT C, POINT D, double R, double Q)
{
    double beginCD, endCD;
    double midCD, midmidCD;
    POINT M;
    POINT Md;
    double min;
    double t1;
    double t2;

    beginCD = 0;
    endCD = 1;
    midCD = (beginCD + endCD) / 2;
    midmidCD = (midCD + endCD) / 2;

    while(endCD - beginCD > 1e-6)
    {
        M = createP(C, D, midCD);
        Md = createP(C, D, midmidCD);
        t1 = distanceTime(N, M, R) + distanceTime(M, D, Q);
        t2 = distanceTime(N, Md, R) + distanceTime(Md, D, Q);
        if(t1 > t2)
        {
            beginCD = midCD;
            midCD = (beginCD + endCD) / 2;
            midmidCD = (midCD + endCD) / 2;
            min = t2;
        }
        else
        {
            endCD = midmidCD;
            midCD = (beginCD + endCD) / 2;
            midmidCD = (midCD + endCD) / 2;
            min = t1;
        }
    }
    return min;
}