Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sundays are good for contests contest
- Loading branch information
Familia
committed
Sep 14, 2008
1 parent
85db1f1
commit 79b4577
Showing
15 changed files
with
444 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
Problem: 3169 - Boundary points | ||
Author: Andrés Mejía-Posada | ||
*/ | ||
|
||
#include <algorithm> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <fstream> | ||
#include <cassert> | ||
#include <climits> | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <string> | ||
#include <cstdio> | ||
#include <vector> | ||
#include <cmath> | ||
#include <queue> | ||
#include <deque> | ||
#include <stack> | ||
#include <map> | ||
#include <set> | ||
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<point> convexHull(vector<point> P){ | ||
int n = P.size(), k = 0; | ||
vector<point> 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<point> 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<point> ans = convexHull(poly); | ||
cout << "(" << ans.front().x << "," << ans.front().y << ")"; | ||
for (int i=1; i<ans.size(); ++i){ | ||
cout << " (" << ans[i].x << "," << ans[i].y << ")"; | ||
} | ||
cout << endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Problem: 3170 - AGTC | ||
Author: Andrés Mejía-Posada | ||
*/ | ||
|
||
#include <algorithm> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <fstream> | ||
#include <cassert> | ||
#include <climits> | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <string> | ||
#include <cstdio> | ||
#include <vector> | ||
#include <cmath> | ||
#include <queue> | ||
#include <deque> | ||
#include <stack> | ||
#include <map> | ||
#include <set> | ||
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] <?= dp[i-1][j] + 1; | ||
if (j) dp[i][j] <?= dp[i][j-1] + 1; | ||
if (i && j) dp[i][j] <?= dp[i-1][j-1] + (s[i] != t[j]); | ||
} | ||
cout << dp[_s][_t] << endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
10 AGTCTGACGC | ||
11 AGTAAGTAGGC | ||
10 AGTCTGACGC | ||
11 AGTAAGTAGGC | ||
6 ANDRES | ||
5 MEJIA |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
Problem: 3171 - Oreon | ||
Author: Andrés Mejía-Posada | ||
*/ | ||
|
||
#include <algorithm> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <fstream> | ||
#include <cassert> | ||
#include <climits> | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <string> | ||
#include <cstdio> | ||
#include <vector> | ||
#include <cmath> | ||
#include <queue> | ||
#include <deque> | ||
#include <stack> | ||
#include <map> | ||
#include <set> | ||
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<edge> ans; | ||
for (int i=0; i<=26; ++i) make_set(i); | ||
for (int i=0; i<n; ++i){ | ||
getline(cin, s); | ||
for (int k=0; k<s.size(); ++k) if (s[k] == ',') s[k] = ' '; | ||
stringstream sin(s); | ||
for (int j=0; j<n; ++j){ | ||
int w; | ||
sin >> w; | ||
if (w) ans.push_back(edge(i+'A', j+'A', w)); | ||
} | ||
} | ||
sort(ans.begin(), ans.end()); | ||
for (int i=0; i<ans.size(); ++i){ | ||
if (find_set(ans[i].u-'A') != find_set(ans[i].v-'A')){ | ||
merge(ans[i].u-'A', ans[i].v-'A'); | ||
cout << ans[i].u << "-" << ans[i].v << " " << ans[i].w << endl; | ||
} | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Problem: 3173 - Wordfish | ||
Author: Andrés Mejía-Posada | ||
*/ | ||
|
||
#include <algorithm> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <fstream> | ||
#include <cassert> | ||
#include <climits> | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <string> | ||
#include <cstdio> | ||
#include <vector> | ||
#include <cmath> | ||
#include <queue> | ||
#include <deque> | ||
#include <stack> | ||
#include <map> | ||
#include <set> | ||
using namespace std; | ||
|
||
int dist(string s){ | ||
int ans = INT_MAX; | ||
int n = s.size(); | ||
for (int i=0; i<n-1; ++i) ans = min(ans, abs(s[i] - s[i+1])); | ||
return ans; | ||
} | ||
|
||
int main(){ | ||
string s; | ||
while (cin >> s){ | ||
assert(s.size() > 1); | ||
|
||
deque<string> 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<string>::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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
WORDFISH | ||
ANDYCITO | ||
ANDY | ||
AB | ||
A | ||
|
Binary file not shown.
Oops, something went wrong.