CF on a youdao similar, did that this much simpler. The idea is to take the mold. Modulo equals 1 how to handle, modulo equals 2 after classification discussion. can be solved.
The data can be sorted before output.
1 /*3029*/2#include <iostream>3#include <string>4#include <map>5#include <queue>6#include <Set>7#include <stack>8#include <vector>9#include <deque>Ten#include <algorithm> One#include <cstdio> A#include <cmath> -#include <ctime> -#include <cstring> the#include <climits> -#include <cctype> -#include <cassert> -#include <functional> + using namespacestd; - //#pragma COMMENT (linker, "/stack:102400000,1024000") + A #defineMpii map<int,int> at #defineVI vector<int> - #definePII pair<int,int> - #defineVpii vector<pair<int,int> > - #defineRep (I, A, n) for (int i=a;i<n;++i) - #definePer (i, a, n) for (int i=n-1;i>=a;--i) - #defineCLR Clear in #definePB Push_back - #defineMP Make_pair to #defineFIR First + #defineSEC Second - #defineAll (x) (x). Begin (), (x). End () the #defineSZ (x) ((int) (x). Size ()) * #defineLson L, Mid, rt<<1 $ #defineRson mid+1, R, rt<<1|1Panax Notoginseng - vi l, R; the + voidDfsintm) { A intTMP = m%3; the intm_; + - if(M = =0) $ return ; $ - if(TMP = =2) { -M_ = m/3+1; the}Else { -M_ = m/3;Wuyi } the - DFS (m_); Wu -Rep (I,0, SZ (l)) AboutL[i] *=3; $Rep (I,0, SZ (r)) -R[i] *=3; - - if(TMP = =2) { AR.PB (1); +}Else if(TMP = =1) { theL.PB (1); - } $ } the the intMain () { theIos::sync_with_stdio (false); the #ifndef Online_judge -Freopen ("data.in","R", stdin); inFreopen ("Data.out","W", stdout); the #endif the About intm; the intLsz, Rsz; the the while(SCANF ("%d", &m)! =EOF) { + l.clear (); - r.clear (); the DFS (m);Bayi Sort (All (l)); the Sort (All (r)); theLSZ =SZ (l); -Rsz =SZ (r); -printf"%d", Rsz); theRep (I,0, Rsz) theprintf"%d", R[i]); thePutchar ('\ n'); the -printf"%d", LSZ); theRep (I,0, LSZ) theprintf"%d", L[i]); thePutchar ('\ n');94 } the the #ifndef Online_judge theprintf"Time =%d.\n", (int) clock ());98 #endif About - return 0;101}
"Hdoj" 3029 Scales