diff --git a/README.md b/README.md index 5524889..3c4f3bd 100644 --- a/README.md +++ b/README.md @@ -36,4 +36,4 @@ Chapter 10: 29/29 Chapter 11: 15/15 -Chapter 12: 0/37 +Chapter 12: 1/37 diff --git a/ch12/UVa12538_rope.cpp b/ch12/UVa12538_rope.cpp new file mode 100644 index 0000000..2144f0b --- /dev/null +++ b/ch12/UVa12538_rope.cpp @@ -0,0 +1,45 @@ +// UVa12538 Version Controlled IDE +// Rujia Liu +// This code makes use of rope, a persistent string available in gcc's STL extensions. +#include +#include +#include +using namespace std; +using namespace __gnu_cxx; + +const int maxn = 50000 + 5; +const int maxlen = 100000 + 5; + +crope cur, versions[maxn]; +char s[maxlen]; + +int main() { + int n; + scanf("%d", &n); // a single test case + int d = 0; + int vnow = 0; + while(n--) { + int op, p, c, v; + scanf("%d", &op); + if(op == 1) { + scanf("%d%s", &p, s); + p -= d; + cur.insert(p, s); + versions[++vnow] = cur; + } + else if(op == 2) { + scanf("%d%d", &p, &c); + p -= d; c -= d; + cur.erase(p-1, c); + versions[++vnow] = cur; + } + else { + scanf("%d%d%d", &v, &p, &c); + p -= d; v -= d; c -= d; + crope r = versions[v].substr(p-1, c); + d += count(r.begin(), r.end(), 'c'); + cout << r << "\n"; + } + } + return 0; +} diff --git a/ch12/readme.md b/ch12/readme.md index 230d0a0..fdce117 100644 --- a/ch12/readme.md +++ b/ch12/readme.md @@ -20,7 +20,7 @@ [暂缺]12-6 UVa1674 Lightning Energy Report -[暂缺]12-7 UVa12538 Version Controlled IDE +12-7 UVa12538 Version Controlled IDE [暂缺]12-8 UVa805 Polygon Intersections diff --git a/ch7/UVa1601.cpp b/ch7/UVa1601.cpp index e44b8ff..9bfe3e7 100644 --- a/ch7/UVa1601.cpp +++ b/ch7/UVa1601.cpp @@ -1,6 +1,7 @@ // UVa1601 The Morning after Halloween // Rujia Liu - +// This code implements the simpliest yet efficient-enough algorithm I'm aware of +// Readers are encouraged to experiment on other algorithms (especially for better efficiency!) #include #include #include @@ -12,13 +13,6 @@ const int maxn = 150; // 75% cells plus 2 fake nodes const int dx[]={1,-1,0,0,0}; // 4 moves, plus "no move" const int dy[]={0,0,1,-1,0}; -/* -char S[16][22]; -int id[16][16],pos[MAXN][2],nums; -int adj[MAXN][5],deg[MAXN]; -int Q[MAXN*MAXN*MAXN],head,tail; -*/ - inline int ID(int a, int b, int c) { return (a<<16)|(b<<8)|c; }