标签:max main span algorithm algo child nbsp ret cout
贪心策略:就是s1+s2>s2+s1这个贪心策略非常容易发现。
#include<iostream> #include<algorithm> #include<string> using namespace std; const int maxn = 55; bool cmp(string s1, string s2){ return s1 + s2 > s2 + s1; } string a[maxn]; int n; int main(){ while (cin >> n){ if (!n)break; for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n, cmp); for (int i = 0; i < n; ++i) cout << a[i]; cout << endl; } }
贪心:Children's Game UVA - 10905
标签:max main span algorithm algo child nbsp ret cout
原文地址:https://www.cnblogs.com/ALINGMAOMAO/p/10909143.html