没参加比赛,就是在Arena中自己做了一下,还是感觉div 2和自己的水平比较匹配。。。。div 1也就能做第一题。
level 1,排序然后扫描即可
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; class PrimalUnlicensedCreatures { public: int maxWins(int, vector <int>); }; int PrimalUnlicensedCreatures::maxWins(int initialLevel, vector <int> grezPower) { int res = 0; int len = grezPower.size(); sort(grezPower.begin(), grezPower.end()); int power = initialLevel; for(int i=0; i<len; i++){ if(power > grezPower[i]){ res++; power += grezPower[i]/2; } else break; } return res; } //<%:testing-code%> //Powered by [KawigiEdit] 2.0!
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; class UndoHistory { public: int minPresses(vector <string>); int presub(string a, string b){ int r = min(a.size(), b.size()); int ans = 0; for(int i=0; i<r; i++){ if(a[i] != b[i]) return i; } return r; } bool check(string master, string slave){ if(master.size() < slave.size()) return false; for(int i=0; i<slave.size(); i++) if(slave[i] != master[i]) return false; return true; } }; int UndoHistory::minPresses(vector <string> lines) { int len = lines.size(); int res = len; int pre[55]; memset(pre, 0, sizeof(pre)); for(int i=0; i<len; i++) for(int j=i-1; j>=0; j--) pre[i] = max(pre[i], presub(lines[j], lines[i])); for(int i=0; i<len; i++){ if(i!=0 && check(lines[i], lines[i-1])==true) res += min(lines[i].size()-lines[i-1].size(), 2+lines[i].size()-pre[i]); else if (i!=0) res += 2+lines[i].size()-pre[i]; else res += lines[i].size(); } return res; } //<%:testing-code%> //Powered by [KawigiEdit] 2.0!
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; class MarblePositioning { public: int len; double res; bool used[10]; vector<int> r; double record[10]; double totalWidth(vector <int>); void solve(double cur, int n, int pre){ if(n==len){ res = min(res, cur); return; } for(int i=0; i<len; i++){ if(used[i] == true) continue; used[i]=true; double tmp = 0; for(int j=0; j<len; j++){ if(used[j]==false || i==j) continue; tmp = max(tmp, record[j]+2.0*sqrt(1.0*r[i]*r[j])); } record[i] = tmp; solve(tmp, n+1, i); used[i]=false; } return; } }; double MarblePositioning::totalWidth(vector <int> radius) { len = radius.size(); r = radius; res = 999999999999LL; memset(used, false, sizeof(used)); memset(record, 0, sizeof(record)); solve(0, 0, -1); return res; } //<%:testing-code%> //Powered by [KawigiEdit] 2.0!