A problem, bear children test eyesight, water problem, test instructions is to judge two numbers corresponding to the number of different digits have how many.
#include <bits/stdc++.h>using namespacestd;classbearcheats{ Public: stringEyesight (intAintB) { intdiga[ the],digb[ the]; intt =0; while(A) {diga[t+ +] = A%Ten; A/=Ten; } for(inti =0; I < T; i++) {Digb[i]= B%Ten; B/=Ten; } intDIF =0; for(inti =0; I < T; i++){ if(Diga[i]!=digb[i]) dif++; } if(dif<=1)return "Happy"; Else return "glasses"; }};
Pro A
b, bear children merge stones, test instructions is to give you three piles of stones, each time you can choose two, set a small heap of stones for X, the big heap of stones for y,x into 2*x,y into y-x. It is impossible to ask the same number of stones in the end.
DIV2 data, the violence of Dfs is over. Because the total number of stones must be, the state can be only two dimensions.
#include <bits/stdc++.h>using namespacestd;Const intMAXN =501;BOOLVIS[MAXN][MAXN];BOOLDfsint*dat) { if(dat[0] = = dat[1] && dat[1] = = dat[2])return true; intndat[3]= {dat[0]<<1, dat[1]-dat[0],dat[2]}; Sort (Ndat,ndat+3); if(!vis[ndat[0]][ndat[1]] && (vis[ndat[0]][ndat[1]] =true, DFS (Ndat)))return true; ndat[0] = dat[0]<<1; ndat[1] = dat[1]; ndat[2] = dat[2]-dat[0]; Sort (Ndat,ndat+3); if(!vis[ndat[0]][ndat[1]] && (vis[ndat[0]][ndat[1]] =true, DFS (Ndat)))return true; ndat[0] = dat[0]; ndat[1] = dat[1]<<1; ndat[2] = dat[2]-dat[1]; Sort (Ndat,ndat+3); if(!vis[ndat[0]][ndat[1]] && (vis[ndat[0]][ndat[1]] =true, DFS (Ndat)))return true; return false;}classbearplaysdiv2{ Public: stringEqualpiles (intAintBintC) { if((A+B+C)/3*3! = a+b+c)return "Impossible"; intdat[3] ={a,b,c}; Sort (Dat,dat+3); vis[dat[0]][dat[1]] =true; if(Dfs (DAT))return "possible"; Else return "Impossible"; }};
Pro B
C, Bear kids sort, bear kids mess up a less function, the probability of returning true and false is half, asking the probability that a sequence of sequential sequences is given after sort. The map will be done.
#include <bits/stdc++.h>using namespacestd;Const intMAXN =550;intA[MAXN];intT[MAXN];Const Doubleonecmp = log (0.5);intTimes ;voidMerge_sort (intAintLintR) { if(r-l<=1)return ; intMid = (l+r) >>1; Merge_sort (A,l,mid); Merge_sort (A,MID,R); inti = l, j = Mid, k =l,p; while(I < mid && J <R) { if(Times++,a[i]>=a[j]) t[k] = a[j++]; ElseT[k] = a[i++]; K++; } if(i = = mid) for(P = j; p < R; p++) t[k++] =A[p]; Else for(p = i; p < mid; p++) t[k++] =A[p]; for(k = l;k < r; k++) A[k] =t[k];}classbearsortsdiv2{ Public: DoubleGetprobability (Vector <int>seq) { for(inti =0; I < seq.size (); i++) {A[seq[i]-1] =i; } Times=0; Merge_sort (A,0, Seq.size ());//log (ans);d ouble ans = returnTimes*onecmp; }}bear;/*int main () {freopen ("In.txt", "R", stdin); Vector<int> s; int tmp; while (~SCANF ("%d", &tmp)) S.push_back (TMP); Double ans = bear.getprobability (s); printf ("%lf", ans); return 0;}*/
View Code
Topcpder SRM 664 div2 a,b,c bearcheats eyesight x bearplays equalpiles x bearsorts getprobability