Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2)

做得我都变绿了!

Problems

# Name    
A

Team Olympiad

standard input/output

1 s, 256 MB

 x2377
B

Queue

standard input/output

2 s, 256 MB

 x1250
C

Hacking Cypher

standard input/output

1 s, 256 MB

 x740
D

Chocolate

standard input/output

1 s, 256 MB

 x397
E

Restoring Increasing Sequence

standard input/output

1 s, 256 MB

 x239
F

Treeland Tour

standard input/output

5 s, 256 MB

 x87

A 水题,开三个vector搞

  1 /** Header .. **/ //{
  2 //#pragma comment(linker, "/STACK:102400000,102400000")
  3 #include<cmath>
  4 #include<ctime>
  5 #include<cstdio>
  6 #include<cstring>
  7 #include<climits>
  8 #include<cstdlib>
  9 #include<iostream>
 10 #include<map>
 11 #include<set>
 12 #include<list>
 13 #include<stack>
 14 #include<queue>
 15 #include<vector>
 16 #include<bitset>
 17 #include<algorithm>
 18 #include<functional>
 19
 20 using namespace std;
 21 #define ALL(A) A.begin(), A.end()
 22 #define LLA(A) A.rbegin(), A.rend()
 23 #define mz(array) memset(array, 0, sizeof(array))
 24 #define mf1(array) memset(array, -1, sizeof(array))
 25 #define minf(array) memset(array, 0x3f, sizeof(array))
 26 #define REP(i,n) for(i=0;i<(n);i++)
 27 #define REP_1(i,n) for (i=1;i<=n;++i)
 28 #define FOR(i,x,y) for(i=x;i<=y;i++)
 29 #define FORD(i,x,y) for(i=x;i>=y;i--)
 30 #define RE  freopen("caravan.in","r",stdin)
 31 #define WE  freopen("caravan.out","w",stdout)
 32 #define mp make_pair
 33 #define pb push_back
 34 #define pf push_front
 35 #define ppf pop_front
 36 #define ppb pop_back
 37 #define lson l, m, rt << 1
 38 #define rson m + 1, r, rt << 1 | 1
 39 #define Rush for(int ____T=RD(); ____T--;)
 40 #define TR(x) while(scanf("%d",&x)!=EOF)
 41 #define Display(A, n, m) {                       42   REP(i, n){                                     43         REP(j, m-1) cout << A[i][j] << " ";      44         cout << A[i][m-1] << endl;                 45     }                                             46 }
 47 #define Display_1(A, n, m) {                     48     REP_1(i, n){                                 49         REP_1(j, m-1) cout << A[i][j] << " ";    50         cout << A[i][m] << endl;                 51     }                                             52 }
 53
 54 typedef long long LL;
 55 typedef unsigned long long uLL;
 56 typedef double DB;
 57 typedef long double LD;
 58 typedef unsigned uint;
 59
 60 typedef vector<int> VI;
 61 typedef vector<char> VC;
 62 typedef vector<string> VS;
 63 typedef vector<LL> VL;
 64 typedef vector<DB> VF;
 65 typedef set<int> SI;
 66 typedef set<string> SS;
 67 typedef map<int, int> MII;
 68 typedef map<string, int> MSI;
 69 typedef pair<int, int> PII;
 70 typedef pair<LL, LL> PLL;
 71 typedef vector<PII> VII;
 72 typedef vector<VI> VVI;
 73 typedef vector<VII> VVII;
 74
 75
 76 template<class T> inline T& RD(T &);
 77 template<class T> inline void OT(const T &);
 78 //inline int RD(){int x; return RD(x);}
 79 inline LL RD(){LL x; return RD(x);}
 80 inline DB& RF(DB &);
 81 inline DB RF(){DB x; return RF(x);}
 82 inline char* RS(char *s);
 83 inline char& RC(char &c);
 84 inline char RC();
 85 inline char& RC(char &c){scanf(" %c", &c); return c;}
 86 inline char RC(){char c; return RC(c);}
 87 //inline char& RC(char &c){c = getchar(); return c;}
 88 //inline char RC(){return getchar();}
 89
 90 template<class T> inline T& RDD(T &);
 91 inline LL RDD(){LL x; return RDD(x);}
 92
 93 template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;}
 94 template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;}
 95 template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;}
 96 template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;}
 97 template<class T0, class T1, class T2, class T3, class T4, class T5> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;}
 98 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;}
 99 template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);}
100 template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);}
101 template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}
102 template<class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}
103 template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}
104 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}
105 inline char& RC(char &a, char &b){RC(a), RC(b); return a;}
106 inline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;}
107 inline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;}
108 inline char& RC(char &a, char &b, char &c, char &d, char &e){RC(a), RC(b), RC(c), RC(d), RC(e); return a;}
109 inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a;}
110 inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a;}
111 inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;}
112 inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;}
113 inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;}
114 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;}
115 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;}
116 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;}
117 inline void RS(char *s1, char *s2){RS(s1), RS(s2);}
118 inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);}
119 template<class T0,class T1>inline T0& RDD(T0&a, T1&b){RDD(a),RDD(b); return a;}
120 template<class T0,class T1,class T2>inline T1& RDD(T0&a, T1&b, T2&c){RDD(a),RDD(b),RDD(c); return a;}
121 //}
122 /** Constant List .. **/ //{
123
124 const int gx[] = {0, 1, 0, -1};
125 const int gy[] = {1, 0, -1, 0};
126 const int MOD = int(1e9) + 7;
127 const int INF = 0x3f3f3f3f;
128 const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
129 const double PI=acos(-1.0);
130 const double EPS=1e-8;
131
132 //}
133 /** Add On .. **/ //{
134 template<class T> inline bool odd(T x){return x&1;}
135 template<class T> inline bool even(T x){return !odd(x);}
136 template<class T> inline T lowbit(T x) {return x & -x;}
137
138 template<class T> inline bool checkMin(T &a,const T b){return b < a ? a = b, 1 : 0;}
139 template<class T> inline bool checkMax(T &a,const T b){return a < b ? a = b, 1 : 0;}
140 template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
141 template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}
142 template<class T> inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}
143 template<class T> inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));}
144 template<class T> inline T min(T a, T b, T c, T d, T e){return min(min(min(a,b),min(c,d)),e);}
145 template<class T> inline T max(T a, T b, T c, T d, T e){return max(max(max(a,b),max(c,d)),e);}
146 template<class T> inline T sqr(T a){return a*a;}
147 template<class T> inline T cub(T a){return a*a*a;}
148 template<class T> T abs(T x){return x>0?x:-x;}
149 inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;}
150 inline int sgn(DB x, DB y){return sgn(x - y);}
151
152 inline DB cos(DB a, DB b, DB c){return (sqr(a)+sqr(b)-sqr(c))/(2*a*b);}
153 inline DB cot(DB x){return 1./tan(x);};
154 inline DB sec(DB x){return 1./cos(x);};
155 inline DB csc(DB x){return 1./sin(x);};
156 //}
157 /** I/O Accelerator Interface .. **/ //{
158 #define g (c=getchar())
159 #define d isdigit(g)
160 #define p x=x*10+c-‘0‘
161 #define n x=x*10+‘0‘-c
162 #define pp l/=10,p
163 #define nn l/=10,n
164 template<class T> inline T& RD(T &x){
165     char c;while(!d);x=c-‘0‘;while(d)p;
166     return x;
167 }
168 template<class T> inline T& RDD(T &x){
169     char c;while(g,c!=‘-‘&&!isdigit(c));
170     if (c==‘-‘){x=‘0‘-g;while(d)n;}
171     else{x=c-‘0‘;while(d)p;}
172     return x;
173 }
174 inline DB& RF(DB &x){
175     //scanf("%lf", &x);
176     char c;while(g,c!=‘-‘&&c!=‘.‘&&!isdigit(c));
177     if(c==‘-‘)if(g==‘.‘){x=0;DB l=1;while(d)nn;x*=l;}
178         else{x=‘0‘-c;while(d)n;if(c==‘.‘){DB l=1;while(d)nn;x*=l;}}
179     else if(c==‘.‘){x=0;DB l=1;while(d)pp;x*=l;}
180         else{x=c-‘0‘;while(d)p;if(c==‘.‘){DB l=1;while(d)pp;x*=l;}}
181     return x;
182 }
183 #undef nn
184 #undef pp
185 #undef n
186 #undef p
187 #undef d
188 #undef g
189 inline char* RS(char *s){
190     //gets(s);
191     scanf("%s", s);
192     return s;
193 }
194
195 int Case=0;template<class T> inline void OT(const T &x){
196     //printf("Case #%d: ", ++Case);
197     //printf("%I64d\n", x);
198     //printf("%.9f\n", x);
199     printf("%d\n", x);
200     //cout << x << endl;
201     //last_ans = x;
202 }
203 //}/* .................................................................................................................................. */
204 /** My Add Part .. **/ //{
205 template<class T>inline void OA(const T &a,const int &st,const int &ed){
206     if(ed>=st)cout<<a[st];
207     int i;
208     FOR(i,st+1,ed)cout<<‘ ‘<<a[i];
209     puts("");
210 }
211 //}
212
213
214 VI a[4];
215 int n;
216 int main(){
217     int i,x;
218     RD(n);
219     FOR(i,1,n){
220         RD(x);
221         a[x].pb(i);
222     }
223     int ans=min(a[1].size() , a[2].size(), a[3].size());
224     OT(ans);
225     REP(i,ans){
226         printf("%d %d %d\n",a[1][i],a[2][i],a[3][i]);
227     }
228     return 0;
229 }

B 哇,有点碉,主要我们找到第一个和第二个,然后分别隔一个搞一个就搞完了。

  1 /** Header .. **/ //{
  2 //#pragma comment(linker, "/STACK:102400000,102400000")
  3 #include<cmath>
  4 #include<ctime>
  5 #include<cstdio>
  6 #include<cstring>
  7 #include<climits>
  8 #include<cstdlib>
  9 #include<iostream>
 10 #include<map>
 11 #include<set>
 12 #include<list>
 13 #include<stack>
 14 #include<queue>
 15 #include<vector>
 16 #include<bitset>
 17 #include<algorithm>
 18 #include<functional>
 19
 20 using namespace std;
 21 #define ALL(A) A.begin(), A.end()
 22 #define LLA(A) A.rbegin(), A.rend()
 23 #define mz(array) memset(array, 0, sizeof(array))
 24 #define mf1(array) memset(array, -1, sizeof(array))
 25 #define minf(array) memset(array, 0x3f, sizeof(array))
 26 #define REP(i,n) for(i=0;i<(n);i++)
 27 #define REP_1(i,n) for (i=1;i<=n;++i)
 28 #define FOR(i,x,y) for(i=x;i<=y;i++)
 29 #define FORD(i,x,y) for(i=x;i>=y;i--)
 30 #define RE  freopen("caravan.in","r",stdin)
 31 #define WE  freopen("caravan.out","w",stdout)
 32 #define mp make_pair
 33 #define pb push_back
 34 #define pf push_front
 35 #define ppf pop_front
 36 #define ppb pop_back
 37 #define lson l, m, rt << 1
 38 #define rson m + 1, r, rt << 1 | 1
 39 #define Rush for(int ____T=RD(); ____T--;)
 40 #define TR(x) while(scanf("%d",&x)!=EOF)
 41 #define Display(A, n, m) {                       42   REP(i, n){                                     43         REP(j, m-1) cout << A[i][j] << " ";      44         cout << A[i][m-1] << endl;                 45     }                                             46 }
 47 #define Display_1(A, n, m) {                     48     REP_1(i, n){                                 49         REP_1(j, m-1) cout << A[i][j] << " ";    50         cout << A[i][m] << endl;                 51     }                                             52 }
 53
 54 typedef long long LL;
 55 typedef unsigned long long uLL;
 56 typedef double DB;
 57 typedef long double LD;
 58 typedef unsigned uint;
 59
 60 typedef vector<int> VI;
 61 typedef vector<char> VC;
 62 typedef vector<string> VS;
 63 typedef vector<LL> VL;
 64 typedef vector<DB> VF;
 65 typedef set<int> SI;
 66 typedef set<string> SS;
 67 typedef map<int, int> MII;
 68 typedef map<string, int> MSI;
 69 typedef pair<int, int> PII;
 70 typedef pair<LL, LL> PLL;
 71 typedef vector<PII> VII;
 72 typedef vector<VI> VVI;
 73 typedef vector<VII> VVII;
 74
 75
 76 template<class T> inline T& RD(T &);
 77 template<class T> inline void OT(const T &);
 78 //inline int RD(){int x; return RD(x);}
 79 inline LL RD(){LL x; return RD(x);}
 80 inline DB& RF(DB &);
 81 inline DB RF(){DB x; return RF(x);}
 82 inline char* RS(char *s);
 83 inline char& RC(char &c);
 84 inline char RC();
 85 inline char& RC(char &c){scanf(" %c", &c); return c;}
 86 inline char RC(){char c; return RC(c);}
 87 //inline char& RC(char &c){c = getchar(); return c;}
 88 //inline char RC(){return getchar();}
 89
 90 template<class T> inline T& RDD(T &);
 91 inline LL RDD(){LL x; return RDD(x);}
 92
 93 template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;}
 94 template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;}
 95 template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;}
 96 template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;}
 97 template<class T0, class T1, class T2, class T3, class T4, class T5> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;}
 98 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;}
 99 template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);}
100 template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);}
101 template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}
102 template<class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}
103 template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}
104 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}
105 inline char& RC(char &a, char &b){RC(a), RC(b); return a;}
106 inline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;}
107 inline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;}
108 inline char& RC(char &a, char &b, char &c, char &d, char &e){RC(a), RC(b), RC(c), RC(d), RC(e); return a;}
109 inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a;}
110 inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a;}
111 inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;}
112 inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;}
113 inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;}
114 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;}
115 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;}
116 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;}
117 inline void RS(char *s1, char *s2){RS(s1), RS(s2);}
118 inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);}
119 template<class T0,class T1>inline T0& RDD(T0&a, T1&b){RDD(a),RDD(b); return a;}
120 template<class T0,class T1,class T2>inline T1& RDD(T0&a, T1&b, T2&c){RDD(a),RDD(b),RDD(c); return a;}
121 //}
122 /** Constant List .. **/ //{
123
124 const int gx[] = {0, 1, 0, -1};
125 const int gy[] = {1, 0, -1, 0};
126 const int MOD = int(1e9) + 7;
127 const int INF = 0x3f3f3f3f;
128 const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
129 const double PI=acos(-1.0);
130 const double EPS=1e-8;
131
132 //}
133 /** Add On .. **/ //{
134 template<class T> inline bool odd(T x){return x&1;}
135 template<class T> inline bool even(T x){return !odd(x);}
136 template<class T> inline T lowbit(T x) {return x & -x;}
137
138 template<class T> inline bool checkMin(T &a,const T b){return b < a ? a = b, 1 : 0;}
139 template<class T> inline bool checkMax(T &a,const T b){return a < b ? a = b, 1 : 0;}
140 template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
141 template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}
142 template<class T> inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}
143 template<class T> inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));}
144 template<class T> inline T min(T a, T b, T c, T d, T e){return min(min(min(a,b),min(c,d)),e);}
145 template<class T> inline T max(T a, T b, T c, T d, T e){return max(max(max(a,b),max(c,d)),e);}
146 template<class T> inline T sqr(T a){return a*a;}
147 template<class T> inline T cub(T a){return a*a*a;}
148 template<class T> T abs(T x){return x>0?x:-x;}
149 inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;}
150 inline int sgn(DB x, DB y){return sgn(x - y);}
151
152 inline DB cos(DB a, DB b, DB c){return (sqr(a)+sqr(b)-sqr(c))/(2*a*b);}
153 inline DB cot(DB x){return 1./tan(x);};
154 inline DB sec(DB x){return 1./cos(x);};
155 inline DB csc(DB x){return 1./sin(x);};
156 //}
157 /** I/O Accelerator Interface .. **/ //{
158 #define g (c=getchar())
159 #define d isdigit(g)
160 #define p x=x*10+c-‘0‘
161 #define n x=x*10+‘0‘-c
162 #define pp l/=10,p
163 #define nn l/=10,n
164 template<class T> inline T& RD(T &x){
165     char c;while(!d);x=c-‘0‘;while(d)p;
166     return x;
167 }
168 template<class T> inline T& RDD(T &x){
169     char c;while(g,c!=‘-‘&&!isdigit(c));
170     if (c==‘-‘){x=‘0‘-g;while(d)n;}
171     else{x=c-‘0‘;while(d)p;}
172     return x;
173 }
174 inline DB& RF(DB &x){
175     //scanf("%lf", &x);
176     char c;while(g,c!=‘-‘&&c!=‘.‘&&!isdigit(c));
177     if(c==‘-‘)if(g==‘.‘){x=0;DB l=1;while(d)nn;x*=l;}
178         else{x=‘0‘-c;while(d)n;if(c==‘.‘){DB l=1;while(d)nn;x*=l;}}
179     else if(c==‘.‘){x=0;DB l=1;while(d)pp;x*=l;}
180         else{x=c-‘0‘;while(d)p;if(c==‘.‘){DB l=1;while(d)pp;x*=l;}}
181     return x;
182 }
183 #undef nn
184 #undef pp
185 #undef n
186 #undef p
187 #undef d
188 #undef g
189 inline char* RS(char *s){
190     //gets(s);
191     scanf("%s", s);
192     return s;
193 }
194
195 int Case=0;template<class T> inline void OT(const T &x){
196     //printf("Case #%d: ", ++Case);
197     //printf("%I64d\n", x);
198     //printf("%.9f\n", x);
199     printf("%d\n", x);
200     //cout << x << endl;
201     //last_ans = x;
202 }
203 //}/* .................................................................................................................................. */
204 /** My Add Part .. **/ //{
205 template<class T>inline void OA(const T &a,const int &st,const int &ed){
206     if(ed>=st)cout<<a[st];
207     int i;
208     FOR(i,st+1,ed)cout<<‘ ‘<<a[i];
209     puts("");
210 }
211 //}
212
213
214 int a[222222];
215 int b[222222];
216 int j2[1111111];
217 int op[1111111];
218 int ed[1111111];
219 int an[222222];
220 int n;
221 int st;
222 int main(){
223     int i,j,x,y;
224     RD(n);
225     FOR(i,1,n){
226         RD(a[i],b[i]);
227         if(a[i]==0){
228             st=i;
229         }
230         op[a[i]]++;
231         ed[b[i]]++;
232         j2[a[i]]=b[i];
233     }
234     i=j2[0];
235     j=1;
236     while(1){
237         an[j]=i;
238         j+=2;
239         i=j2[i];
240         if(i==0)break;
241     }
242     FOR(i,1,1000000)if(op[i]==1 && ed[i]==0)break;
243     j=0;
244     while(1){
245         an[j]=i;
246         j+=2;
247         i=j2[i];
248         if(i==0)break;
249     }
250     printf("%d",an[0]);
251     FOR(i,1,n-1)printf(" %d",an[i]);
252     puts("");
253     return 0;
254 }

C 我搞了个java果然FST了!There is a hole in my brain! 其实可以搞出前缀余和后缀余的嘛!

  1 /** Header .. **/ //{
  2 //#pragma comment(linker, "/STACK:102400000,102400000")
  3 #include<cmath>
  4 #include<ctime>
  5 #include<cstdio>
  6 #include<cstring>
  7 #include<climits>
  8 #include<cstdlib>
  9 #include<iostream>
 10 #include<map>
 11 #include<set>
 12 #include<list>
 13 #include<stack>
 14 #include<queue>
 15 #include<vector>
 16 #include<bitset>
 17 #include<algorithm>
 18 #include<functional>
 19
 20 using namespace std;
 21 #define ALL(A) A.begin(), A.end()
 22 #define LLA(A) A.rbegin(), A.rend()
 23 #define mz(array) memset(array, 0, sizeof(array))
 24 #define mf1(array) memset(array, -1, sizeof(array))
 25 #define minf(array) memset(array, 0x3f, sizeof(array))
 26 #define REP(i,n) for(i=0;i<(n);i++)
 27 #define REP_1(i,n) for (i=1;i<=n;++i)
 28 #define FOR(i,x,y) for(i=x;i<=y;i++)
 29 #define FORD(i,x,y) for(i=x;i>=y;i--)
 30 #define RE  freopen("caravan.in","r",stdin)
 31 #define WE  freopen("caravan.out","w",stdout)
 32 #define mp make_pair
 33 #define pb push_back
 34 #define pf push_front
 35 #define ppf pop_front
 36 #define ppb pop_back
 37 #define lson l, m, rt << 1
 38 #define rson m + 1, r, rt << 1 | 1
 39 #define Rush for(int ____T=RD(); ____T--;)
 40 #define TR(x) while(scanf("%d",&x)!=EOF)
 41 #define Display(A, n, m) {                       42   REP(i, n){                                     43         REP(j, m-1) cout << A[i][j] << " ";      44         cout << A[i][m-1] << endl;                 45     }                                             46 }
 47 #define Display_1(A, n, m) {                     48     REP_1(i, n){                                 49         REP_1(j, m-1) cout << A[i][j] << " ";    50         cout << A[i][m] << endl;                 51     }                                             52 }
 53
 54 typedef long long LL;
 55 typedef unsigned long long uLL;
 56 typedef double DB;
 57 typedef long double LD;
 58 typedef unsigned uint;
 59
 60 typedef vector<int> VI;
 61 typedef vector<char> VC;
 62 typedef vector<string> VS;
 63 typedef vector<LL> VL;
 64 typedef vector<DB> VF;
 65 typedef set<int> SI;
 66 typedef set<string> SS;
 67 typedef map<int, int> MII;
 68 typedef map<string, int> MSI;
 69 typedef pair<int, int> PII;
 70 typedef pair<LL, LL> PLL;
 71 typedef vector<PII> VII;
 72 typedef vector<VI> VVI;
 73 typedef vector<VII> VVII;
 74
 75
 76 template<class T> inline T& RD(T &);
 77 template<class T> inline void OT(const T &);
 78 //inline int RD(){int x; return RD(x);}
 79 inline LL RD(){LL x; return RD(x);}
 80 inline DB& RF(DB &);
 81 inline DB RF(){DB x; return RF(x);}
 82 inline char* RS(char *s);
 83 inline char& RC(char &c);
 84 inline char RC();
 85 inline char& RC(char &c){scanf(" %c", &c); return c;}
 86 inline char RC(){char c; return RC(c);}
 87 //inline char& RC(char &c){c = getchar(); return c;}
 88 //inline char RC(){return getchar();}
 89
 90 template<class T> inline T& RDD(T &);
 91 inline LL RDD(){LL x; return RDD(x);}
 92
 93 template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;}
 94 template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;}
 95 template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;}
 96 template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;}
 97 template<class T0, class T1, class T2, class T3, class T4, class T5> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;}
 98 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;}
 99 template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);}
100 template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);}
101 template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}
102 template<class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}
103 template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}
104 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}
105 inline char& RC(char &a, char &b){RC(a), RC(b); return a;}
106 inline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;}
107 inline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;}
108 inline char& RC(char &a, char &b, char &c, char &d, char &e){RC(a), RC(b), RC(c), RC(d), RC(e); return a;}
109 inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a;}
110 inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a;}
111 inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;}
112 inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;}
113 inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;}
114 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;}
115 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;}
116 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;}
117 inline void RS(char *s1, char *s2){RS(s1), RS(s2);}
118 inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);}
119 template<class T0,class T1>inline T0& RDD(T0&a, T1&b){RDD(a),RDD(b); return a;}
120 template<class T0,class T1,class T2>inline T1& RDD(T0&a, T1&b, T2&c){RDD(a),RDD(b),RDD(c); return a;}
121 //}
122 /** Constant List .. **/ //{
123
124 const int gx[] = {0, 1, 0, -1};
125 const int gy[] = {1, 0, -1, 0};
126 const int MOD = int(1e9) + 7;
127 const int INF = 0x3f3f3f3f;
128 const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
129 const double PI=acos(-1.0);
130 const double EPS=1e-8;
131
132 //}
133 /** Add On .. **/ //{
134 template<class T> inline bool odd(T x){return x&1;}
135 template<class T> inline bool even(T x){return !odd(x);}
136 template<class T> inline T lowbit(T x) {return x & -x;}
137
138 template<class T> inline bool checkMin(T &a,const T b){return b < a ? a = b, 1 : 0;}
139 template<class T> inline bool checkMax(T &a,const T b){return a < b ? a = b, 1 : 0;}
140 template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
141 template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}
142 template<class T> inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}
143 template<class T> inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));}
144 template<class T> inline T min(T a, T b, T c, T d, T e){return min(min(min(a,b),min(c,d)),e);}
145 template<class T> inline T max(T a, T b, T c, T d, T e){return max(max(max(a,b),max(c,d)),e);}
146 template<class T> inline T sqr(T a){return a*a;}
147 template<class T> inline T cub(T a){return a*a*a;}
148 template<class T> T abs(T x){return x>0?x:-x;}
149 inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;}
150 inline int sgn(DB x, DB y){return sgn(x - y);}
151
152 inline DB cos(DB a, DB b, DB c){return (sqr(a)+sqr(b)-sqr(c))/(2*a*b);}
153 inline DB cot(DB x){return 1./tan(x);};
154 inline DB sec(DB x){return 1./cos(x);};
155 inline DB csc(DB x){return 1./sin(x);};
156 //}
157 /** I/O Accelerator Interface .. **/ //{
158 #define g (c=getchar())
159 #define d isdigit(g)
160 #define p x=x*10+c-‘0‘
161 #define n x=x*10+‘0‘-c
162 #define pp l/=10,p
163 #define nn l/=10,n
164 template<class T> inline T& RD(T &x){
165     char c;while(!d);x=c-‘0‘;while(d)p;
166     return x;
167 }
168 template<class T> inline T& RDD(T &x){
169     char c;while(g,c!=‘-‘&&!isdigit(c));
170     if (c==‘-‘){x=‘0‘-g;while(d)n;}
171     else{x=c-‘0‘;while(d)p;}
172     return x;
173 }
174 inline DB& RF(DB &x){
175     //scanf("%lf", &x);
176     char c;while(g,c!=‘-‘&&c!=‘.‘&&!isdigit(c));
177     if(c==‘-‘)if(g==‘.‘){x=0;DB l=1;while(d)nn;x*=l;}
178         else{x=‘0‘-c;while(d)n;if(c==‘.‘){DB l=1;while(d)nn;x*=l;}}
179     else if(c==‘.‘){x=0;DB l=1;while(d)pp;x*=l;}
180         else{x=c-‘0‘;while(d)p;if(c==‘.‘){DB l=1;while(d)pp;x*=l;}}
181     return x;
182 }
183 #undef nn
184 #undef pp
185 #undef n
186 #undef p
187 #undef d
188 #undef g
189 inline char* RS(char *s){
190     //gets(s);
191     scanf("%s", s);
192     return s;
193 }
194
195 int Case=0;template<class T> inline void OT(const T &x){
196     //printf("Case #%d: ", ++Case);
197     //printf("%I64d\n", x);
198     //printf("%.9f\n", x);
199     printf("%d\n", x);
200     //cout << x << endl;
201     //last_ans = x;
202 }
203 //}/* .................................................................................................................................. */
204 /** My Add Part .. **/ //{
205 template<class T>inline void OA(const T &a,const int &st,const int &ed){
206     if(ed>=st)cout<<a[st];
207     int i;
208     FOR(i,st+1,ed)cout<<‘ ‘<<a[i];
209     puts("");
210 }
211 //}
212
213
214 const int maxn=1111111;
215 char s[maxn];
216 int l[maxn],r[maxn];
217 int a,b;
218
219 int ans;
220 int n;
221
222 bool farm(){
223     int i,j;
224     n=strlen(s);
225     mz(r);
226     mz(l);
227     l[0]=s[0]-‘0‘;
228     l[0]%=a;
229     FOR(i,1,n-1){
230         l[i]=l[i-1]*10 + s[i]-‘0‘;
231         l[i]%=a;
232     }
233
234     r[n-1] = s[n-1]-‘0‘;
235     r[n-1]%=b;
236     j=10;
237     FORD(i,n-2,1){
238         r[i]=j*(s[i]-‘0‘) + r[i+1];
239         r[i]%=b;
240         j*=10;
241         j%=b;
242     }
243     FOR(i,1,n-1){
244         //printf("%d: %d,%d\n",i,l[i-1],r[i]);
245         if(s[i]!=‘0‘ && l[i-1]==0 && r[i]==0){
246             ans=i;
247             return 1;
248         }
249     }
250     return 0;
251 }
252
253 int main(){
254     int i,j,x,y;
255     RS(s);
256     RD(a,b);
257     if(farm()){
258         puts("YES");
259         REP(i,ans)putchar(s[i]);
260         puts("");
261         FOR(i,ans,n-1)putchar(s[i]);
262         puts("");
263     }else puts("NO");
264     return 0;
265 }

D 我搞了个BFS果然FST了! There is a hole in my brain! 其实我对这种约数的都不太懂,数学硬伤。这个题我们只能除以2或者除以3嘛,我们就把它面积搞成有相同个数的因数二和相同个数的因数三就行,搞完了他们还不等我们也没办法,就输出不行。

  1 /** Header .. **/ //{
  2 //#pragma comment(linker, "/STACK:102400000,102400000")
  3 #include<cmath>
  4 #include<ctime>
  5 #include<cstdio>
  6 #include<cstring>
  7 #include<climits>
  8 #include<cstdlib>
  9 #include<iostream>
 10 #include<map>
 11 #include<set>
 12 #include<list>
 13 #include<stack>
 14 #include<queue>
 15 #include<vector>
 16 #include<bitset>
 17 #include<algorithm>
 18 #include<functional>
 19
 20 using namespace std;
 21 #define ALL(A) A.begin(), A.end()
 22 #define LLA(A) A.rbegin(), A.rend()
 23 #define mz(array) memset(array, 0, sizeof(array))
 24 #define mf1(array) memset(array, -1, sizeof(array))
 25 #define minf(array) memset(array, 0x3f, sizeof(array))
 26 #define REP(i,n) for(i=0;i<(n);i++)
 27 #define REP_1(i,n) for (i=1;i<=n;++i)
 28 #define FOR(i,x,y) for(i=x;i<=y;i++)
 29 #define FORD(i,x,y) for(i=x;i>=y;i--)
 30 #define RE  freopen("caravan.in","r",stdin)
 31 #define WE  freopen("caravan.out","w",stdout)
 32 #define mp make_pair
 33 #define pb push_back
 34 #define pf push_front
 35 #define ppf pop_front
 36 #define ppb pop_back
 37 #define lson l, m, rt << 1
 38 #define rson m + 1, r, rt << 1 | 1
 39 #define Rush for(int ____T=RD(); ____T--;)
 40 #define TR(x) while(scanf("%d",&x)!=EOF)
 41 #define Display(A, n, m) {                       42   REP(i, n){                                     43         REP(j, m-1) cout << A[i][j] << " ";      44         cout << A[i][m-1] << endl;                 45     }                                             46 }
 47 #define Display_1(A, n, m) {                     48     REP_1(i, n){                                 49         REP_1(j, m-1) cout << A[i][j] << " ";    50         cout << A[i][m] << endl;                 51     }                                             52 }
 53
 54 typedef long long LL;
 55 typedef unsigned long long uLL;
 56 typedef double DB;
 57 typedef long double LD;
 58 typedef unsigned uint;
 59
 60 typedef vector<int> VI;
 61 typedef vector<char> VC;
 62 typedef vector<string> VS;
 63 typedef vector<LL> VL;
 64 typedef vector<DB> VF;
 65 typedef set<int> SI;
 66 typedef set<string> SS;
 67 typedef map<int, int> MII;
 68 typedef map<string, int> MSI;
 69 typedef pair<int, int> PII;
 70 typedef pair<LL, LL> PLL;
 71 typedef vector<PII> VII;
 72 typedef vector<VI> VVI;
 73 typedef vector<VII> VVII;
 74
 75
 76 template<class T> inline T& RD(T &);
 77 template<class T> inline void OT(const T &);
 78 //inline int RD(){int x; return RD(x);}
 79 inline LL RD() {
 80     LL x;
 81     return RD(x);
 82 }
 83 inline DB& RF(DB &);
 84 inline DB RF() {
 85     DB x;
 86     return RF(x);
 87 }
 88 inline char* RS(char *s);
 89 inline char& RC(char &c);
 90 inline char RC();
 91 inline char& RC(char &c) {
 92     scanf(" %c", &c);
 93     return c;
 94 }
 95 inline char RC() {
 96     char c;
 97     return RC(c);
 98 }
 99 //inline char& RC(char &c){c = getchar(); return c;}
100 //inline char RC(){return getchar();}
101
102 template<class T> inline T& RDD(T &);
103 inline LL RDD() {
104     LL x;
105     return RDD(x);
106 }
107
108 template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1) {
109     RD(x0), RD(x1);
110     return x0;
111 }
112 template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2) {
113     RD(x0), RD(x1), RD(x2);
114     return x0;
115 }
116 template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) {
117     RD(x0), RD(x1), RD(x2), RD(x3);
118     return x0;
119 }
120 template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) {
121     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);
122     return x0;
123 }
124 template<class T0, class T1, class T2, class T3, class T4, class T5> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {
125     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);
126     return x0;
127 }
128 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) {
129     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);
130     return x0;
131 }
132 template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1) {
133     OT(x0), OT(x1);
134 }
135 template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2) {
136     OT(x0), OT(x1), OT(x2);
137 }
138 template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3) {
139     OT(x0), OT(x1), OT(x2), OT(x3);
140 }
141 template<class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4) {
142     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);
143 }
144 template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5) {
145     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);
146 }
147 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6) {
148     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);
149 }
150 inline char& RC(char &a, char &b) {
151     RC(a), RC(b);
152     return a;
153 }
154 inline char& RC(char &a, char &b, char &c) {
155     RC(a), RC(b), RC(c);
156     return a;
157 }
158 inline char& RC(char &a, char &b, char &c, char &d) {
159     RC(a), RC(b), RC(c), RC(d);
160     return a;
161 }
162 inline char& RC(char &a, char &b, char &c, char &d, char &e) {
163     RC(a), RC(b), RC(c), RC(d), RC(e);
164     return a;
165 }
166 inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f) {
167     RC(a), RC(b), RC(c), RC(d), RC(e), RC(f);
168     return a;
169 }
170 inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g) {
171     RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g);
172     return a;
173 }
174 inline DB& RF(DB &a, DB &b) {
175     RF(a), RF(b);
176     return a;
177 }
178 inline DB& RF(DB &a, DB &b, DB &c) {
179     RF(a), RF(b), RF(c);
180     return a;
181 }
182 inline DB& RF(DB &a, DB &b, DB &c, DB &d) {
183     RF(a), RF(b), RF(c), RF(d);
184     return a;
185 }
186 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e) {
187     RF(a), RF(b), RF(c), RF(d), RF(e);
188     return a;
189 }
190 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f) {
191     RF(a), RF(b), RF(c), RF(d), RF(e), RF(f);
192     return a;
193 }
194 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g) {
195     RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g);
196     return a;
197 }
198 inline void RS(char *s1, char *s2) {
199     RS(s1), RS(s2);
200 }
201 inline void RS(char *s1, char *s2, char *s3) {
202     RS(s1), RS(s2), RS(s3);
203 }
204 template<class T0,class T1>inline T0& RDD(T0&a, T1&b) {
205     RDD(a),RDD(b);
206     return a;
207 }
208 template<class T0,class T1,class T2>inline T1& RDD(T0&a, T1&b, T2&c) {
209     RDD(a),RDD(b),RDD(c);
210     return a;
211 }
212 //}
213 /** Constant List .. **/ //{
214
215 const int gx[] = {0, 1, 0, -1};
216 const int gy[] = {1, 0, -1, 0};
217 const int MOD = int(1e9) + 7;
218 const int INF = 0x3f3f3f3f;
219 const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
220 const double PI=acos(-1.0);
221 const double EPS=1e-8;
222
223 //}
224 /** Add On .. **/ //{
225 template<class T> inline bool odd(T x) {
226     return x&1;
227 }
228 template<class T> inline bool even(T x) {
229     return !odd(x);
230 }
231 template<class T> inline T lowbit(T x) {
232     return x & -x;
233 }
234
235 template<class T> inline bool checkMin(T &a,const T b) {
236     return b < a ? a = b, 1 : 0;
237 }
238 template<class T> inline bool checkMax(T &a,const T b) {
239     return a < b ? a = b, 1 : 0;
240 }
241 template<class T> inline T min(T a, T b, T c) {
242     return min(min(a, b), c);
243 }
244 template<class T> inline T max(T a, T b, T c) {
245     return max(max(a, b), c);
246 }
247 template<class T> inline T min(T a, T b, T c, T d) {
248     return min(min(a, b), min(c, d));
249 }
250 template<class T> inline T max(T a, T b, T c, T d) {
251     return max(max(a, b), max(c, d));
252 }
253 template<class T> inline T min(T a, T b, T c, T d, T e) {
254     return min(min(min(a,b),min(c,d)),e);
255 }
256 template<class T> inline T max(T a, T b, T c, T d, T e) {
257     return max(max(max(a,b),max(c,d)),e);
258 }
259 template<class T> inline T sqr(T a) {
260     return a*a;
261 }
262 template<class T> inline T cub(T a) {
263     return a*a*a;
264 }
265 template<class T> T abs(T x) {
266     return x>0?x:-x;
267 }
268 inline int sgn(DB x) {
269     return x < -EPS ? -1 : x > EPS;
270 }
271 inline int sgn(DB x, DB y) {
272     return sgn(x - y);
273 }
274
275 inline DB cos(DB a, DB b, DB c) {
276     return (sqr(a)+sqr(b)-sqr(c))/(2*a*b);
277 }
278 inline DB cot(DB x) {
279     return 1./tan(x);
280 };
281 inline DB sec(DB x) {
282     return 1./cos(x);
283 };
284 inline DB csc(DB x) {
285     return 1./sin(x);
286 };
287 //}
288 /** I/O Accelerator Interface .. **/ //{
289 #define g (c=getchar())
290 #define d isdigit(g)
291 #define p x=x*10+c-‘0‘
292 #define n x=x*10+‘0‘-c
293 #define pp l/=10,p
294 #define nn l/=10,n
295 template<class T> inline T& RD(T &x) {
296     char c;
297     while(!d);
298     x=c-‘0‘;
299     while(d)p;
300     return x;
301 }
302 template<class T> inline T& RDD(T &x) {
303     char c;
304     while(g,c!=‘-‘&&!isdigit(c));
305     if (c==‘-‘) {
306         x=‘0‘-g;
307         while(d)n;
308     } else {
309         x=c-‘0‘;
310         while(d)p;
311     }
312     return x;
313 }
314 inline DB& RF(DB &x) {
315     //scanf("%lf", &x);
316     char c;
317     while(g,c!=‘-‘&&c!=‘.‘&&!isdigit(c));
318     if(c==‘-‘)if(g==‘.‘) {
319             x=0;
320             DB l=1;
321             while(d)nn;
322             x*=l;
323         } else {
324             x=‘0‘-c;
325             while(d)n;
326             if(c==‘.‘) {
327                 DB l=1;
328                 while(d)nn;
329                 x*=l;
330             }
331         }
332     else if(c==‘.‘) {
333         x=0;
334         DB l=1;
335         while(d)pp;
336         x*=l;
337     } else {
338         x=c-‘0‘;
339         while(d)p;
340         if(c==‘.‘) {
341             DB l=1;
342             while(d)pp;
343             x*=l;
344         }
345     }
346     return x;
347 }
348 #undef nn
349 #undef pp
350 #undef n
351 #undef p
352 #undef d
353 #undef g
354 inline char* RS(char *s) {
355     //gets(s);
356     scanf("%s", s);
357     return s;
358 }
359
360 int Case=0;
361 template<class T> inline void OT(const T &x) {
362     //printf("Case #%d: ", ++Case);
363     //printf("%I64d\n", x);
364     //printf("%.9f\n", x);
365     printf("%d\n", x);
366     //cout << x << endl;
367     //last_ans = x;
368 }
369 //}/* .................................................................................................................................. */
370 /** My Add Part .. **/ //{
371 template<class T>inline void OA(const T &a,const int &st,const int &ed) {
372     if(ed>=st)cout<<a[st];
373     int i;
374     FOR(i,st+1,ed)cout<<‘ ‘<<a[i];
375     puts("");
376 }
377 //}
378
379 int a0,b0,a1,b1;
380
381 int farm() {
382     int i, j, k, x , y ,z;
383     int t0=0 , t1 = 0;
384     LL t;
385     t=(LL)a0 * b0;
386     while(t%3==0) t/=3, t0++;
387     t=(LL)a1 * b1;
388     while(t%3==0) t/=3, t1++;
389     int ans = abs(t0-t1);
390     while(t0>t1){
391         if(a0%3==0)a0=a0*2/3;
392         else b0=b0*2/3;
393         t0--;
394     }
395     while(t1>t0){
396         if(a1%3==0)a1=a1*2/3;
397         else b1=b1*2/3;
398         t1--;
399     }
400     t=(LL)a0*b0;
401     t0=t1=0;
402     while(t%2==0)t/=2, t0++;
403     t=(LL)a1*b1;
404     while(t%2==0)t/=2, t1++;
405     ans+=abs(t0-t1);
406     while(t0>t1){
407         if(a0%2==0)a0=a0/2;
408         else b0=b0/2;
409         t0--;
410     }
411     while(t1>t0){
412         if(a1%2==0)a1=a1/2;
413         else b1=b1/2;
414         t1--;
415     }
416     if((LL)a0*b0 == (LL)a1*b1)return ans;
417     return -1;
418 }
419
420 int main() {
421     RD(a0, b0, a1, b1 );
422     int ans=farm();
423     OT(ans);
424     if(ans!=-1) {
425         printf("%d %d\n%d %d\n",a0, b0, a1, b1);
426     }
427     return 0;
428 }

现在我已经不是职业选手了,只好当娱乐解说了。不过我还是想,至少上一下传说!

为了上传说首先我使用了禁忌的秘术-岛娘的头文件,虽然还用的不是很熟

然后这场开了个新小号打div2,体验从4往1做的套路,然后34都FST了,居然变绿了,我都尿。

明明上次的第四题是暴力题!这次的我不太擅长。不过为了上传说当然要熟悉各种套路才行。

时间: 2024-10-03 23:27:47

Codeforces Round #279 (Div. 2) ABCD的相关文章

Codeforces Round #279 (Div. 2) b

/**  * @brief Codeforces Round #279 (Div. 2) b  * @file b.cpp  * @author mianma  * @created 2014/11/27 15:29  * @edited  2014/11/27 20:40  * @type   * @note  */ #include <cstdio> #include <stack> #include <cstring> #include <vector>

Codeforces Round #279 (Div. 2) a

/**  * @brief Codeforces Round #279 (Div. 2) a  * @file a.cpp  * @author 面码  * @created 2014/11/26 17:05  * @edited  2014/11/26 17:05  * @type   *  */ #include <cstdio> #include <stack> #include <cstring> using namespace std; #define max

Codeforces Round #279 (Div. 2) d

/**  * @brief Codeforces Round #279 (Div. 2) d  * @file d.cpp  * @author 面码  * @created 2014/12/09 10:58  * @edited  2014/12/09 10:58  * @type math greedy  * @note 自己的AC不了,参考别人的,重点是2和3都是质数,所以可以使用贪心求解.  */ #include <fstream> #include <iostream>

Codeforces Round #258 (Div. 2)[ABCD]

Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意: Akshat and Malvika两人玩一个游戏,横竖n,m根木棒排成#型,每次取走一个交点,交点相关的横竖两条木棒要去掉,Akshat先手,给出n,m问谁赢. 分析: 水题,很明显不管拿掉哪个点剩下的都是(n-1,m-1),最后状态是(0,x)或(x,0),也就是拿了min(n,m)-1次,

Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T

Codeforces Round #279 (Div. 2) 题解集合

终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心什么的乱搞,貌似放A题难了 1 #include <cstdio> 2 #include <algorithm> 3 4 using namespace std; 5 const int N = 5005; 6 7 int cnt[5], first[5], next[N]; 8 9

Codeforces Round #Pi (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/567 听说Round #Pi的意思是Round #314... A. Lineland Mail time limit per test:3 seconds memory limit per test:256 megabytes All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with it

Codeforces Round #250 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory limit per test:256 megabytes Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between th

Codeforces Round #143 (Div. 2) (ABCD 思维场)

题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test:256 megabytes One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually