andmej/live-archive

Sundays are good for contests contest

andmej committed Sep 14, 2008
1 parent 85db1f1 commit 79b4577b7402437459aedd68bd3dac7a847764dc
Binary file not shown.
 @@ -0,0 +1,90 @@ +/* + Problem: 3169 - Boundary points + Author: Andrés Mejía-Posada + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +struct point { + double x, y; + point(){} point(double x, double y) : x(x), y(y) {} + bool operator <(const point &p) const { + return x < p.x || (x == p.x && y < p.y); + } +}; + +// 2D cross product. +// Return a positive value, if OAB makes a counter-clockwise turn, +// negative for clockwise turn, and zero if the points are collinear. +double cross(const point &O, const point &A, const point &B){ + double d = (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x); + if (fabs(d) < 1e-9) return 0.0; + return d; +} + +// Returns a list of points on the convex hull in counter-clockwise order. +// Note: the last point in the returned list is the same as the first one. +vector convexHull(vector P){ + int n = P.size(), k = 0; + vector H(2*n); + + // Sort points lexicographically + sort(P.begin(), P.end()); + + // Build lower hull + for (int i = 0; i < n; i++) { + while (k >= 2 && cross(H[k-2], H[k-1], P[i]) <= 0.0) k--; + H[k++] = P[i]; + } + + // Build upper hull + for (int i = n-2, t = k+1; i >= 0; i--) { + while (k >= t && cross(H[k-2], H[k-1], P[i]) <= 0.0) k--; + H[k++] = P[i]; + } + + H.resize(k); + return H; +} + +int main(){ + string s; + while (getline(cin, s)){ + stringstream splitter(s); + string pnt; + vector poly; + while (splitter >> pnt){ + assert(pnt.size() > 3); + pnt[0] = pnt[pnt.size()-1] = pnt[pnt.find(',')] = ' '; + stringstream sin(pnt); + double x, y; + sin >> x >> y; + poly.push_back(point(x, y)); + } + + vector ans = convexHull(poly); + cout << "(" << ans.front().x << "," << ans.front().y << ")"; + for (int i=1; i
 @@ -0,0 +1 @@ +(-2,1) (-1,-2) (-1,1) (-1,2) (-1,3) (0,0) (1,-1) (1,1) (2,-2) (2,1) (3,2)
Binary file not shown.
 @@ -0,0 +1,43 @@ +/* + Problem: 3170 - AGTC + Author: Andrés Mejía-Posada + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +int main(){ + string s, t; + int _s, _t; + while (cin >> _s >> s >> _t >> t){ + s = " " + s, t = " " + t; + int dp[_s+1][_t+1]; + dp[0][0] = 0; + for (int i=0; i<=_s; ++i) + for (int j=0; j<=_t; ++j) + if (i || j){ + dp[i][j] = INT_MAX; + if (i) dp[i][j]
 @@ -0,0 +1,6 @@ +10 AGTCTGACGC +11 AGTAAGTAGGC +10 AGTCTGACGC +11 AGTAAGTAGGC +6 ANDRES +5 MEJIA
Binary file not shown.
 @@ -0,0 +1,75 @@ +/* + Problem: 3171 - Oreon + Author: Andrés Mejía-Posada + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +/* Union find */ +int p[27], rank[27]; +void make_set(int x){ p[x] = x, rank[x] = 0; } +void link(int x, int y){ rank[x] > rank[y] ? p[y] = x : p[x] = y, rank[x] == rank[y] ? rank[y]++: 0; } +int find_set(int x){ return x != p[x] ? p[x] = find_set(p[x]) : p[x]; } +void merge(int x, int y){ link(find_set(x), find_set(y)); } +/* End union find */ + + +struct edge{ + int w; + char u, v; + edge(){} edge(char U, char V, int W) : u(min(U, V)), v(max(U, V)), w(W) {} + bool operator < (const edge &that) const { + return ( w < that.w || (w == that.w && u < that.u || (w == that.w && u == that.u && v < that.v))); + } +}; + + +int main(){ + int pizza = 1; + int T; + cin >> T; + while (T--){ + cout << "Case " << pizza++ << ":" << endl; + int n; + cin >> n; + string s; + getline(cin, s); + vector ans; + for (int i=0; i<=26; ++i) make_set(i); + for (int i=0; i> w; + if (w) ans.push_back(edge(i+'A', j+'A', w)); + } + } + sort(ans.begin(), ans.end()); + for (int i=0; i
 @@ -0,0 +1,16 @@ +2 +6 +0, 8, 12, 0, 0, 7 +8, 0, 0, 3, 0, 0 +12, 0, 0, 0, 6, 0 +0, 3, 0, 0, 0, 4 +0, 0, 6, 0, 0, 5 +7, 0, 0, 4, 5, 0 +6 +0, 8, 12, 0, 0, 7 +8, 0, 0, 3, 0, 0 +12, 0, 0, 0, 6, 0 +0, 3, 0, 0, 0, 4 +0, 0, 6, 0, 0, 5 +7, 0, 0, 4, 5, 0 +
Binary file not shown.
 @@ -0,0 +1,66 @@ +/* + Problem: 3173 - Wordfish + Author: Andrés Mejía-Posada + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +int dist(string s){ + int ans = INT_MAX; + int n = s.size(); + for (int i=0; i> s){ + assert(s.size() > 1); + + deque p(1, s); + string t; + + t = s; + for (int i=0; i<10; ++i){ + next_permutation(t.begin(), t.end()); + p.push_back(t); + } + + t = s; + for (int i=0; i<10; ++i){ + prev_permutation(t.begin(), t.end()); + p.push_front(t); + } + + sort(p.begin(), p.end()); //Useless? + + int score = -1; string ans; + for (deque::iterator k = p.begin(); k != p.end(); ++k){ + int t = dist(*k); + if (t > score){ + score = t; + ans = *k; + } + } + cout << ans << score << endl; + + } + return 0; +}
 @@ -0,0 +1,6 @@ +WORDFISH +ANDYCITO +ANDY +AB +A +
Binary file not shown.