标签:
在家里的破电脑上co了这题,怎么说呢,最近效率真是不怎么高,也是有各种杂事拖累,包括论文什么的。
#include<iostream> #include<fstream> using namespace std; string dfs(int N,int R,int P,int S) { if (!N) { if (R) return "R"; if (P) return "P"; if (S) return "S"; } int a,b,c; // a : R vs S -> R // b : P vs R -> P // c : P vs S -> 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; bool f1 = (a+b==R) && (a+c==S) && (b+c==P); bool f2 = (a >= 0) && (b >= 0) && (c >= 0); if (!f1 || !f2) return ""; string lastRound = dfs(N-1,a,b,c); if (lastRound == "") return ""; string ret = ""; for (int i = 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"; } return ret; } string reorder(string s) { int N = s.length(); if (N == 1) return s; string sl = reorder(s.substr(0,N/2)); string sr = reorder(s.substr(N/2,N/2)); if (sl + sr < sr + sl) return sl + sr; else return sr + sl; } int main() { ifstream fin("in.txt"); ofstream fout("out.txt"); int T; fin >> T; int N,R,P,S; for (int t = 0;t < T;t++) { fout << "Case #" << t+1 << ": "; fin >> N >> R >> P >> S; string ans = dfs(N,R,P,S); if (ans == "") fout << "IMPOSSIBLE" << endl; else fout << reorder(ans) << endl; } return 0; }
思路也比较直接,由于不能有平局,其实如果可以安排的话,每一轮的对阵其实已经确定了。
所以一轮一轮确定好,最后用一个递归过程把这些对局在允许的范围内排序就好。
这算是一个好的开始吧,round2的最简单题,只要能前1000就会有T-shirt咯!
I‘m the T-shirt hunter.
【CJ】Rather Perplexing Showdown
标签:
原文地址:http://www.cnblogs.com/soya/p/5572978.html