2018 South-South University Program Design competition: K-Pony Super Brine (binary search)

Source: Internet
Author: User

Link: 2018 South-South University Program Design competition: K-Pony Super Brine

Test instructions: Small Mago Cup brine, Cup has unit of Salt and unit of water. Pony is very bored, so he wants to know how many kinds of this cup of brine non-empty set, pour together after the salt and water ratio is.

Troubleshooting: Binary. MAXN = 35, Direct enumeration is sure to be tle, binary time complexity is enough.

(A1 + A2)/(B1 + B2) = x/y; A1 * Y-B1 * x = B2 * x-a2 * y;

because there are 0 of the existence, the result is to reduce one.

#include <bits/stdc++.h>
using namespace std;

const int MAXN = + Ten;
int n, x, y;
int A[MAXN], B[MAXN];
A long long ans = 0;
Map<long long, int> MP;

void DFS (int l, int r, int A, int B, int flag)
{
    if (L = = r) {
        if (flag) ans + = mp[x * b-y * A];
        else Mp[y * a-x * b]++;
        return;
    }
    DFS (l + 1, R, A, B, flag);
    DFS (l + 1, R, A + a[l], B + b[l], flag);
}

int main ()
{
    int T;
    scanf ("%d", &t);
    while (t--) {
        mp.clear ();
        Ans = 0;

        scanf ("%d%d%d", &n, &x, &y);
        for (int i = 0; i < n; i++) scanf ("%d%d", &a[i], &b[i]);

        DFS (0, N/2, 0, 0, 0);
        DFS (N/2, N, 0, 0, 1);

        printf ("%lld\n", ans-1);
    }

    return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.