Пример #1
0
int main()
{
	while(scanf("%d%d", &n, &m) == 2 && (n || m))
	{
		for(int i = 1; i <= n; i++) black[i].Read();
		for(int i = 1; i <= m; i++) white[i].Read();
		bool flag = 0;
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= m; j++)
			{
				if(black[i].x == white[j].x)
					flag |= solve1(black[i].x);
				if(black[i].y == white[j].y)
					flag |= solve2(black[i].y);
				else {
					int by = black[i].y, bx = black[i].x;
					int wy = white[j].y, wx = white[j].x;
					double k = 1.0 * (wy - by) / (wx - bx);
					double b = by - k * bx;
					flag |= solve3(k, b);
				}
			}
		if(flag) puts("YES"); else puts("NO");
	}
	return 0;
}
Пример #2
0
int main(){
    scanf("%d %d %d",&n,&q,&k);
    if(k == 1){
        solve3();
        return 0;
    }
    else{
        for (int i=1; i<=n; i++) {
            scanf("%d",&a[i]);
            seg.add(i,1,n,1,a[i]);
        }
        for (int i=0; i<q; i++) {
            int t;
            scanf("%d",&t);
            if(t == 1){
                int u, b;
                scanf("%d %d",&u,&b);
                seg.add(u,1,n,1,b);
            }
            if(t == 2){
                int s,e;
                scanf("%d %d",&s,&e);
                seg.move(s,e,1,n,1);
            }
            if(t == 3){
                int s,e;
                scanf("%d %d",&s,&e);
                printf("%lld\n",seg.sum(s,e,1,n,1));
            }
        }
    }
}
Пример #3
0
unsigned int solve4 (int n, int a, int b, int c)
{
    int i;
    unsigned int res = 0;

    //    printf ("solve4 (%d, %d, %d, %d)\n", n, a, b, c);

    for (i = 0; i <= a && i <= n; i++)
        res += solve3 (n-i, b, c);

    return res;
}
Пример #4
0
Coloring Problem::solve(int exercise, int runs) const {
    if (runs < 1) {
        throw std::out_of_range("La cantidad de corridas debe ser mayor a 0");
    }

    switch (exercise) {
        case 1:
            for (auto i = 0; i < runs - 1; ++i) {
                solve1();
            }

            return solve1();
        case 2:
            for (auto i = 0; i < runs - 1; ++i) {
                solve2();
            }

            return solve2();
        case 3:
            for (auto i = 0; i < runs - 1; ++i) {
                solve3();
            }

            return solve3();
        case 4:
            for (auto i = 0; i < runs - 1; ++i) {
                solve4();
            }

            return solve4();
        case 5:
            for (auto i = 0; i < runs - 1; ++i) {
                solve5();
            }

            return solve5();
        default:
            throw std::out_of_range("Los ejercicios estan numerados del 1 al 5");
    }
}
Пример #5
0
  std::pair<v2_t<num_t>, num_t> closest_point(v2_t<num_t> pos) const {
    v2_t<num_t> p = pos - p0;
    num_t p1p = v2_t<num_t>::dot(p1, p);
    num_t p2p = v2_t<num_t>::dot(p2, p);

    std::vector<num_t> sol = solve3(A, B, C - p2p + num_t(2) * p1p, -p1p);
    num_t d;
    num_t min_dist = p.lengthsq();
    v2_t<num_t> min_pos = v2_t<num_t>::zero();
    num_t min_t = num_t(0);

    d = (p - p2).lengthsq();
    if (d < min_dist) {
      min_dist = d;
      min_pos = p2;
      min_t = num_t(1);
    }

    for (size_t i = 0; i < sol.size(); ++i) {
      if (sol[i] > num_t(0) && sol[i] < num_t(1)) {
        v2_t<num_t> q = get_relpos(sol[i]);
        d = (p - q).lengthsq();
        if (d < min_dist) {
          min_dist = d;
          min_pos = q;
          min_t = sol[i];
        }
      }
    }

    min_dist = ::sqrt(min_dist);
    if (v2_t<num_t>::orient(min_pos, min_pos + get_tangent(min_t), p) <
        num_t(0)) {
      min_dist = -min_dist;
    }

    return std::make_pair(min_pos + p0, min_dist);
  }
Пример #6
0
static int splineintersectsline (Ppoint_t *sps, Ppoint_t *lps,
        double *roots) {
    double scoeff[4], xcoeff[2], ycoeff[2];
    double xroots[3], yroots[3], tv, sv, rat;
    int rootn, xrootn, yrootn, i, j;

    xcoeff[0] = lps[0].x;
    xcoeff[1] = lps[1].x - lps[0].x;
    ycoeff[0] = lps[0].y;
    ycoeff[1] = lps[1].y - lps[0].y;
    rootn = 0;
    if (xcoeff[1] == 0) {
        if (ycoeff[1] == 0) {
            points2coeff (sps[0].x, sps[1].x, sps[2].x, sps[3].x, scoeff);
            scoeff[0] -= xcoeff[0];
            xrootn = solve3 (scoeff, xroots);
            points2coeff (sps[0].y, sps[1].y, sps[2].y, sps[3].y, scoeff);
            scoeff[0] -= ycoeff[0];
            yrootn = solve3 (scoeff, yroots);
            if (xrootn == 4)
                if (yrootn == 4)
                    return 4;
                else
                    for (j = 0; j < yrootn; j++)
                        addroot (yroots[j], roots, &rootn);
            else if (yrootn == 4)
                for (i = 0; i < xrootn; i++)
                    addroot (xroots[i], roots, &rootn);
            else
                for (i = 0; i < xrootn; i++)
                    for (j = 0; j < yrootn; j++)
                        if (xroots[i] == yroots[j])
                            addroot (xroots[i], roots, &rootn);
            return rootn;
        } else {
            points2coeff (sps[0].x, sps[1].x, sps[2].x, sps[3].x, scoeff);
            scoeff[0] -= xcoeff[0];
            xrootn = solve3 (scoeff, xroots);
            if (xrootn == 4)
                return 4;
            for (i = 0; i < xrootn; i++) {
                tv = xroots[i];
                if (tv >= 0 && tv <= 1) {
                    points2coeff (sps[0].y, sps[1].y, sps[2].y, sps[3].y,
                            scoeff);
                    sv = scoeff[0] + tv * (scoeff[1] + tv *
                        (scoeff[2] + tv * scoeff[3]));
                    sv = (sv - ycoeff[0]) / ycoeff[1];
                    if ((0 <= sv) && (sv <= 1))
                        addroot (tv, roots, &rootn);
                }
            }
            return rootn;
        }
    } else {
        rat = ycoeff[1] / xcoeff[1];
        points2coeff (sps[0].y - rat * sps[0].x, sps[1].y - rat * sps[1].x,
                sps[2].y - rat * sps[2].x, sps[3].y - rat * sps[3].x, scoeff);
        scoeff[0] += rat * xcoeff[0] - ycoeff[0];
        xrootn = solve3 (scoeff, xroots);
        if (xrootn == 4)
            return 4;
        for (i = 0; i < xrootn; i++) {
            tv = xroots[i];
            if (tv >= 0 && tv <= 1) {
                points2coeff (sps[0].x, sps[1].x, sps[2].x, sps[3].x, scoeff);
                sv = scoeff[0] + tv * (scoeff[1] + tv *
                    (scoeff[2] + tv * scoeff[3]));
                sv = (sv - xcoeff[0]) / xcoeff[1];
                if ((0 <= sv) && (sv <= 1))
                    addroot (tv, roots, &rootn);
            }
        }
        return rootn;
    }
}