In the home of the broken Computer Co on this question, how to say, the recent efficiency is not very high, but also a variety of chores dragged down, including papers and so on.
#include <iostream>#include<fstream>using namespacestd;stringDfsintNintRintPintS) { if(!N) {ifRreturn "R"; ifPreturn "P"; ifSreturn "S"; } intA,b,c; //a:r vs S-R//b:p vs R-P//C:p vs S /*------------------------| A + b = R | A + c = S | B + c = P \-------------------------*/a= (R + s-p)/2; b= (R + p-s)/2; C= (S + p-r)/2; BOOLF1 = (a+b==r) && (a+c==s) && (b+c==P); BOOLF2 = (a >=0) && (b >=0) && (c >=0); if(!f1 | |!f2)return ""; stringLastround = DFS (n1, A,b,c); if(Lastround = ="")return ""; stringRET =""; for(inti =0; I<lastround.length (); i++) { if(Lastround[i] = ='R') ret = ret +"RS"; if(Lastround[i] = ='P') ret = ret +"PR"; if(Lastround[i] = ='S') ret = ret +"PS"; } returnret;}stringReorderstrings) { intN =s.length (); if(N = =1)returns; stringSL = Reorder (S.SUBSTR (0, n/2)); stringsr = Reorder (S.SUBSTR (n/2, n/2)); if(SL + SR < SR + SL)returnSL +SR; Else returnSR +SL; }intMain () {ifstream fin ("In.txt"); Ofstream Fout ("OUT.txt"); intT; Fin>>T; intN,r,p,s; for(intt =0; t < t;t++) {Fout<<"Case #"<< t+1<<": "; Fin>> N >> R >> P >>S; stringAns =DFS (n,r,p,s); if(ans = ="") Fout <<"Impossible"<<Endl; ElseFout << Reorder (ans) <<Endl; } return 0;}
The idea is also more direct, because there can be no draw, in fact, if it is possible to arrange, each round of the match has actually been determined.
So it's OK to round round and finally use a recursive process to sort the matches within the allowed range.
This is a good start, round2 the simplest problem, as long as the first 1000 will have T-shirt!
I ' m the T-shirt hunter.
"CJ" rather perplexing showdown