Codeforces 342A Xenia and divisors (water problem)

Source: Internet
Author: User

Test instructions: given n number (less than or equal to 7), let you divide it into M-groups, each group has three numbers, and satisfies, a < b < C, and a can be divisible by b,b divisible by C.

Analysis: For this problem, because the topic said is not more than 7, then a think not on the three groups, 124,136,126. In the three groups, and then determine the number of each group, first only the second group has 3, then the number of the second group is determined,

Then look at the remaining two groups, only the first group has 4, then the first group is determined, then the rest is the third group, of course, the third group only 6.

The code is as follows:

#include <bits/stdc++.h>using namespace Std;const int maxn = 33333 + 5;typedef long Long ll;int a[10];int main () {
   int n, x;    while (CIN >> N) {        memset (a, 0, sizeof (a));        for (int i = 0; i < n; ++i) {            cin >> x;            ++A[X];        }        int m = N/3;        bool OK = true;        if (A[5] | | a[7]) OK = false;        if (A[1] < a[3] | | a[6] < a[3]) OK = false;        A[1]-= a[3], a[6]-= a[3];        int a1 = a[3];        if (a[1]! = a[2] | | a[6] + a[4]! = a[2]) ok = false;        int a2 = a[6];        int a4 = a[4];        if (!ok)  printf (" -1\n");        else{for            (int i = 0; i < A1; ++i)  printf ("1 3 6\n");            for (int i = 0; i < A2; ++i)  printf ("1 2 6\n");            for (int i = 0; i < A4; ++i)  printf ("1 2 4\n");        }    }    return 0;}

Codeforces 342A Xenia and divisors (water problem)

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.