Codeforces Round #279 (Div. 2) ABCDE

Codeforces Round #279 (Div. 2)

做得我都变绿了!

Problems
 
 
#Name  
A
standard input/output
1 s, 256 MB
Submit Add to favourites  x2377
B
standard input/output
2 s, 256 MB
Submit Add to favourites  x1250
C
standard input/output
1 s, 256 MB
Submit Add to favourites  x740
D
standard input/output
1 s, 256 MB
Submit Add to favourites  x397
E
standard input/output
1 s, 256 MB
Submit Add to favourites  x239
F
standard input/output
5 s, 256 MB
Submit Add to favourites  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 }
View Code

 

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 }
View Code

 

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 }
View Code

 

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 }
View Code

 

E 哇,竟然是乱搞大水题,我都怕

  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 mz(array) memset(array, 0, sizeof(array))
 22 #define mf1(array) memset(array, -1, sizeof(array))
 23 #define minf(array) memset(array, 0x3f, sizeof(array))
 24 #define REP(i,n) for(i=0;i<(n);i++)
 25 #define REP_1(i,n) for (i=1;i<=n;++i)
 26 #define FOR(i,x,y) for(i=x;i<=y;i++)
 27 #define FORD(i,x,y) for(i=x;i>=y;i--)
 28 #define RE  freopen("caravan.in","r",stdin)
 29 #define WE  freopen("caravan.out","w",stdout)
 30 #define lson l, m, rt << 1
 31 #define rson m + 1, r, rt << 1 | 1
 32 #define Rush for(int ____T=RD(); ____T--;)
 33 #define TR(x) while(scanf("%d",&x)!=EOF)
 34 #define ALL(A) A.begin(), A.end()
 35 #define LLA(A) A.rbegin(), A.rend()
 36 #define CPY(A, B) memcpy(A, B, sizeof(A))
 37 #define INS(A, P, B) A.insert(A.begin() + P, B)
 38 #define ERS(A, P) A.erase(A.begin() + P)
 39 #define LBD(A, x) (lower_bound(ALL(A), x) - A.begin())
 40 #define UBD(A, x) (upper_bound(ALL(A), x) - A.begin())
 41 #define CTN(T, x) (T.find(x) != T.end())
 42 #define SZ(A) int((A).size())
 43 #define PB push_back
 44 #define PPB pop_back
 45 #define PF push_front
 46 #define PPF pop_front
 47 #define MP(A, B) make_pair(A, B)
 48 #define Ts *this
 49 #define rTs return Ts
 50 #define fi first
 51 #define se second
 52 #define Display(A, n, m) {                      \
 53   REP(i, n){                                    \
 54         REP(j, m-1) cout << A[i][j] << " ";     \
 55         cout << A[i][m-1] << endl;                \
 56     }                                            \
 57 }
 58 #define Display_1(A, n, m) {                    \
 59     REP_1(i, n){                                \
 60         REP_1(j, m-1) cout << A[i][j] << " ";   \
 61         cout << A[i][m] << endl;                \
 62     }                                            \
 63 }
 64 
 65 typedef long long LL;
 66 typedef unsigned long long uLL;
 67 typedef double DB;
 68 typedef long double LD;
 69 typedef unsigned uint;
 70 
 71 typedef vector<int> VI;
 72 typedef vector<char> VC;
 73 typedef vector<string> VS;
 74 typedef vector<LL> VL;
 75 typedef vector<DB> VF;
 76 typedef set<int> SI;
 77 typedef set<string> SS;
 78 typedef map<int, int> MII;
 79 typedef map<string, int> MSI;
 80 typedef pair<int, int> PII;
 81 typedef pair<LL, LL> PLL;
 82 typedef vector<PII> VII;
 83 typedef vector<VI> VVI;
 84 typedef vector<VII> VVII;
 85 
 86 
 87 template<class T> inline T& RD(T &);
 88 template<class T> inline void OT(const T &);
 89 //inline int RD(){int x; return RD(x);}
 90 inline LL RD() {
 91     LL x;
 92     return RD(x);
 93 }
 94 inline DB& RF(DB &);
 95 inline DB RF() {
 96     DB x;
 97     return RF(x);
 98 }
 99 inline char* RS(char *s);
100 inline char& RC(char &c);
101 inline char RC();
102 inline char& RC(char &c) {
103     scanf(" %c", &c);
104     return c;
105 }
106 inline char RC() {
107     char c;
108     return RC(c);
109 }
110 //inline char& RC(char &c){c = getchar(); return c;}
111 //inline char RC(){return getchar();}
112 
113 template<class T> inline T& RDD(T &);
114 inline LL RDD() {
115     LL x;
116     return RDD(x);
117 }
118 
119 template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1) {
120     RD(x0), RD(x1);
121     return x0;
122 }
123 template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2) {
124     RD(x0), RD(x1), RD(x2);
125     return x0;
126 }
127 template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) {
128     RD(x0), RD(x1), RD(x2), RD(x3);
129     return x0;
130 }
131 template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) {
132     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);
133     return x0;
134 }
135 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) {
136     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);
137     return x0;
138 }
139 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) {
140     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);
141     return x0;
142 }
143 template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1) {
144     OT(x0), OT(x1);
145 }
146 template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2) {
147     OT(x0), OT(x1), OT(x2);
148 }
149 template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3) {
150     OT(x0), OT(x1), OT(x2), OT(x3);
151 }
152 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) {
153     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);
154 }
155 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) {
156     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);
157 }
158 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) {
159     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);
160 }
161 inline char& RC(char &a, char &b) {
162     RC(a), RC(b);
163     return a;
164 }
165 inline char& RC(char &a, char &b, char &c) {
166     RC(a), RC(b), RC(c);
167     return a;
168 }
169 inline char& RC(char &a, char &b, char &c, char &d) {
170     RC(a), RC(b), RC(c), RC(d);
171     return a;
172 }
173 inline char& RC(char &a, char &b, char &c, char &d, char &e) {
174     RC(a), RC(b), RC(c), RC(d), RC(e);
175     return a;
176 }
177 inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f) {
178     RC(a), RC(b), RC(c), RC(d), RC(e), RC(f);
179     return a;
180 }
181 inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g) {
182     RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g);
183     return a;
184 }
185 inline DB& RF(DB &a, DB &b) {
186     RF(a), RF(b);
187     return a;
188 }
189 inline DB& RF(DB &a, DB &b, DB &c) {
190     RF(a), RF(b), RF(c);
191     return a;
192 }
193 inline DB& RF(DB &a, DB &b, DB &c, DB &d) {
194     RF(a), RF(b), RF(c), RF(d);
195     return a;
196 }
197 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e) {
198     RF(a), RF(b), RF(c), RF(d), RF(e);
199     return a;
200 }
201 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f) {
202     RF(a), RF(b), RF(c), RF(d), RF(e), RF(f);
203     return a;
204 }
205 inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g) {
206     RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g);
207     return a;
208 }
209 inline void RS(char *s1, char *s2) {
210     RS(s1), RS(s2);
211 }
212 inline void RS(char *s1, char *s2, char *s3) {
213     RS(s1), RS(s2), RS(s3);
214 }
215 template<class T0,class T1>inline T0& RDD(T0&a, T1&b) {
216     RDD(a),RDD(b);
217     return a;
218 }
219 template<class T0,class T1,class T2>inline T1& RDD(T0&a, T1&b, T2&c) {
220     RDD(a),RDD(b),RDD(c);
221     return a;
222 }
223 template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}
224 template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}
225 template<class T> inline void CLR(T &A){A.clear();}
226 
227 template<class T0, class T1> inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);}
228 template<class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);}
229 template<class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3){RST(A0), RST(A1), RST(A2), RST(A3);}
230 template<class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}
231 template<class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}
232 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}
233 template<class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);}
234 template<class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x);}
235 template<class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x);}
236 template<class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x);}
237 template<class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x);}
238 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x);}
239 template<class T> inline void CLR(priority_queue<T, vector<T>, less<T> > &Q){while (!Q.empty()) Q.pop();}
240 template<class T> inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q){while (!Q.empty()) Q.pop();}
241 template<class T> inline void CLR(stack<T> &S){while (!S.empty()) S.pop();}
242 template<class T> inline void CLR(queue<T> &Q){while (!Q.empty()) Q.pop();}
243 
244 
245 //}
246 /** Constant List .. **/ //{
247 
248 const int gx[] = {0, 1, 0, -1};
249 const int gy[] = {1, 0, -1, 0};
250 const int MOD = int(1e9) + 7;
251 const int INF = 0x3f3f3f3f;
252 const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
253 const double PI=acos(-1.0);
254 const double EPS=1e-8;
255 
256 //}
257 /** Add On .. **/ //{
258 template<class T> inline bool odd(T x) {
259     return x&1;
260 }
261 template<class T> inline bool even(T x) {
262     return !odd(x);
263 }
264 template<class T> inline T lowbit(T x) {
265     return x & -x;
266 }
267 
268 template<class T> inline bool checkMin(T &a,const T b) {
269     return b < a ? a = b, 1 : 0;
270 }
271 template<class T> inline bool checkMax(T &a,const T b) {
272     return a < b ? a = b, 1 : 0;
273 }
274 template<class T> inline T min(T a, T b, T c) {
275     return min(min(a, b), c);
276 }
277 template<class T> inline T max(T a, T b, T c) {
278     return max(max(a, b), c);
279 }
280 template<class T> inline T min(T a, T b, T c, T d) {
281     return min(min(a, b), min(c, d));
282 }
283 template<class T> inline T max(T a, T b, T c, T d) {
284     return max(max(a, b), max(c, d));
285 }
286 template<class T> inline T min(T a, T b, T c, T d, T e) {
287     return min(min(min(a,b),min(c,d)),e);
288 }
289 template<class T> inline T max(T a, T b, T c, T d, T e) {
290     return max(max(max(a,b),max(c,d)),e);
291 }
292 template<class T> inline T sqr(T a) {
293     return a*a;
294 }
295 template<class T> inline T cub(T a) {
296     return a*a*a;
297 }
298 template<class T> T abs(T x) {
299     return x>0?x:-x;
300 }
301 inline int sgn(DB x) {
302     return x < -EPS ? -1 : x > EPS;
303 }
304 inline int sgn(DB x, DB y) {
305     return sgn(x - y);
306 }
307 
308 inline DB cos(DB a, DB b, DB c) {
309     return (sqr(a)+sqr(b)-sqr(c))/(2*a*b);
310 }
311 inline DB cot(DB x) {
312     return 1./tan(x);
313 };
314 inline DB sec(DB x) {
315     return 1./cos(x);
316 };
317 inline DB csc(DB x) {
318     return 1./sin(x);
319 };
320 //}
321 /** I/O Accelerator Interface .. **/ //{
322 #define g (c=getchar())
323 #define d isdigit(g)
324 #define p x=x*10+c-'0'
325 #define n x=x*10+'0'-c
326 #define pp l/=10,p
327 #define nn l/=10,n
328 template<class T> inline T& RD(T &x) {
329     char c;
330     while(!d);
331     x=c-'0';
332     while(d)p;
333     return x;
334 }
335 template<class T> inline T& RDD(T &x) {
336     char c;
337     while(g,c!='-'&&!isdigit(c));
338     if (c=='-') {
339         x='0'-g;
340         while(d)n;
341     } else {
342         x=c-'0';
343         while(d)p;
344     }
345     return x;
346 }
347 inline DB& RF(DB &x) {
348     //scanf("%lf", &x);
349     char c;
350     while(g,c!='-'&&c!='.'&&!isdigit(c));
351     if(c=='-')if(g=='.') {
352             x=0;
353             DB l=1;
354             while(d)nn;
355             x*=l;
356         } else {
357             x='0'-c;
358             while(d)n;
359             if(c=='.') {
360                 DB l=1;
361                 while(d)nn;
362                 x*=l;
363             }
364         }
365     else if(c=='.') {
366         x=0;
367         DB l=1;
368         while(d)pp;
369         x*=l;
370     } else {
371         x=c-'0';
372         while(d)p;
373         if(c=='.') {
374             DB l=1;
375             while(d)pp;
376             x*=l;
377         }
378     }
379     return x;
380 }
381 #undef nn
382 #undef pp
383 #undef n
384 #undef p
385 #undef d
386 #undef g
387 inline char* RS(char *s) {
388     //gets(s);
389     scanf("%s", s);
390     return s;
391 }
392 
393 int Case=0;
394 template<class T> inline void OT(const T &x) {
395     //printf("Case #%d: ", ++Case);
396     //printf("%I64d\n", x);
397     //printf("%.9f\n", x);
398     printf("%d\n", x);
399     //cout << x << endl;
400     //last_ans = x;
401 }
402 //}/* .................................................................................................................................. */
403 /** My Add Part .. **/ //{
404 template<class T>inline void OA(const T &a,const int &st,const int &ed) {
405     if(ed>=st)cout<<a[st];
406     int i;
407     FOR(i,st+1,ed)cout<<' '<<a[i];
408     puts("");
409 }
410 //}
411 
412 const int maxn=111111;
413 
414 char s[maxn][11];
415 
416 inline bool gank(int *p, int *a, const int &an, const int &now,const bool &ka){
417 //    int i;
418 //    REP(i,an)printf("%d ",a[i]);
419 //    printf("(%d %d)\n",now,ka);
420     if(now>=an){
421         if(!ka)return 1;
422         else return 0;
423     }
424     if(a[now]==-1){
425         if(!ka){
426             a[now]=0;
427             return gank(p,a,an,now+1,0);
428         }else{
429             a[now]=p[now];
430             if(gank(p,a,an,now+1,1))return 1;
431             a[now]=-1;
432             if(p[now]==9)return 0;
433             a[now]=p[now]+1;
434             if(gank(p,a,an,now+1,0))return 1;
435             a[now]=-1;
436         }
437     }else{
438         if(ka&&(a[now]<p[now]))return 0;
439         return gank(p,a,an,now+1,ka &&(a[now]==p[now]));
440     }
441     return 0;
442 }
443 
444 bool make(int x){
445     int p[11];
446     int pn=0;
447     int i,j,k;
448     for(i=0;s[x-1][i]!='\0';i++){
449         p[pn]=s[x-1][i]-'0';
450         pn++;
451     }
452     int a[11];
453     int an=0;
454     for(i=0;s[x][i]!='\0';i++){
455         if(s[x][i]!='?')a[an]=s[x][i]-'0';
456         else a[an]=-1;
457         an++;
458     }
459     if(an<pn)return 0;
460     if(an==pn){
461         if(!gank(p,a,an,0,1))return 0;
462     }
463     if(an>pn){
464         if(a[0]==-1)a[0]=1;
465         FOR(i,1,an-1)if(a[i]==-1)a[i]=0;
466     }
467     REP(i,an)s[x][i]=a[i]+'0';
468     return 1;
469 }
470 
471 int n;
472 
473 bool farm(){
474     int i;
475     s[0][0]='0';
476     s[0][1]='\0';
477     FOR(i,1,n){
478         if(!make(i))return 0;
479     }
480     return 1;
481 }
482 
483 int main(){
484     int i,j,k;
485     RD(n);
486     FOR(i,1,n){
487         scanf(" %s",s[i]);
488     }
489     if(farm()){
490         puts("YES");
491         FOR(i,1,n)puts(s[i]);
492     }else puts("NO");
493     return 0;
494 }
View Code

 

 

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

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

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

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

posted @ 2014-11-23 23:43  带鱼Yuiffy  阅读(267)  评论(3编辑  收藏  举报