The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online
发布日期:2021-05-24 01:26:26 浏览次数:12 分类:精选文章

本文共 4048 字,大约阅读时间需要 13 分钟。

DREAMGRID 的 Music Game Problem Analysis

DREAMGRID recently finished a music game called "Live Love," and he received a sequence of notes consisting of "PERFECT" and "NON-PERFECT" results. The score of the song is determined by the maximum number of continuous "PERFECT" results in the sequence, known as the max-combo.

Problem Analysis

The sequence's score is the length of the longest consecutive "PERFECT" streak. The challenge is to determine the minimum and maximum possible scores given the total number of "PERFECT" results and the sequence length.

Key Insights

  • Max Score: The maximum possible combo is when all "PERFECT" results appear consecutively. If the number of "PERFECT" results equals the sequence length, the max-combo is the sequence length. If there are not enough "PERFECT" results to fill the entire sequence, the max-combo is the total number of "PERFECT" results.

  • Min Score: To minimize the score, distribute the "PERFECT" results as evenly as possible throughout the sequence. The minimum score is determined by how many "PERFECT" results can be spaced out by at least one "NON-PERFECT" result. For example, if there are m "PERFECT" results, the minimum score is determined by the formula:[\text{min_combo} = \left\lceil \frac{m}{(n - m) + 1} \right\rceil]where n is the sequence length.

  • Solution Code

    #include 
    #include
    #include
    #include
    using namespace std;int main() { int t, n, m; vector
    a(30, 0); scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); // Calculate maximum possible score int maxx = m; if (m == 0) { maxx = 0; } else if (n == m) { maxx = n; } else { maxx = m; } // Calculate minimum possible score int minn = 1; if (m == 0) { minn = 0; } else { int gaps = n - m; if (gaps == 0) { minn = m; } else if (gaps <= m - 1) { minn = 1; } else { minn = (m + gaps - 1) / gaps; } } cout << maxx << " " << minn << endl; } return 0;}

    XOR Clique Problem Analysis

    The problem requires finding the maximum subset of a given sequence where the XOR of any two elements is less than the smaller of the two.

    Key Insights

  • XOR Property: For two numbers, XOR results in a number where the binary representation has 1s only where the two numbers have differing bits.
  • Binary Length: The XOR of two numbers will be less than the smaller number if they have the same binary length. This is because the highest set bit in the XOR will cancel at least one bit from both numbers.
  • Solution Code

    #include 
    #include
    #include
    #include
    using namespace std;int main() { int t, n; vector
    nums; scanf("%d", &t); while (t--) { scanf("%d", &n); nums.clear(); while (n--) { int x = 0; int y = 0; while (nums.size() < 30) { x++; if ((x & 1) == 1) { y |= (1 << (x - 1)); } x >>= 1; } nums.push_back(y); } int max_group = 0; if (!nums.empty()) { int count[30] = {0}; for (int num : nums) { int bits = 0; while (num) { bits++; num >>= 1; } count[bits]++; max_group = max(max_group, count[bits]); } } cout << max_group << endl; } return 0;}

    Summary of Results

    • DREAMGRID Problem: For each test case, compute the maximum and minimum possible scores based on the sequence length and number of "PERFECT" results.
    • XOR Clique Problem: Determine the maximum subset size where the XOR of any two elements is less than the smaller element, achieved by grouping numbers by their binary lengths.
    上一篇:2016ACM/ICPC亚洲区大连站(区域赛练习)
    下一篇:51nod 最小生成树

    发表评论

    最新留言

    不错!
    [***.144.177.141]2025年04月25日 00时19分45秒