"Codeforces 342A" Xenia and divisors

Source: Internet
Author: User

"Link" I am the link, point me:)
Test instructions

Exercises


In the end, there are only 3 cases of a,b,c
1,2,4
1,2,6
1,3,6
Then use Cnt[8] to count the number of occurrences of each number.
Output CNT[4] times 1,2,4
(if 1 or 2 is not enough, then no solution
Followed by
If the number of 6 and the number of 1 is different, then no solution
If the number of 2 times +3 is different from the number of 6 occurrences, then there is no solution.
Otherwise
Output CNT[2] a 1,2,6
CNT[3] A 1,3,6 is OK.
See if there's enough output for N/3 group.
If not enough, there is no solution (indicating that there are other useless numbers appearing

Code

#include <bits/stdc++.h> #define REP1 (I,A,B) for (int i = a;i <= b;i++) using namespace std;const int n = 1e5;int n , M;int cnt[10];vector<pair<int,pair<int,int> > > V;int Main () {ios::sync_with_stdio (0), Cin.tie (0),    Cout.tie (0);    CIN >> N;        for (int i = 1;i <= n;i++) {int x;        CIN >> X;    cnt[x]++;        } rep1 (I,1,cnt[4]) {v.push_back ({1,{2,4}});        if (cnt[1]==0) return cout<< "-1" <<endl,0;        if (cnt[2]==0) return cout<< "-1" <<endl,0;        cnt[1]--;cnt[2]--;    n-=3;    } Cnt[4] = 0; if (Cnt[1]!=cnt[6] | | |        (cnt[2]+cnt[3])! = (Cnt[6])) {cout<< "-1" <<endl;    return 0;        } for (int i = 1;i <= cnt[2];i++) {v.push_back ({1,{2,6}});    n-=3;        } for (int i = 1;i <= cnt[3];i++) {v.push_back ({1,{3,6}});    n-=3;    } if (n!=0) return cout<<-1<<endl,0; for (auto temp:v) {cout<<temp.first<< '' <<temp.second.first<< ' <<temp.second.second<<endl; } return 0;}

"Codeforces 342A" Xenia and divisors

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.