Skip to content

Commit

Permalink
first code for ch12
Browse files Browse the repository at this point in the history
  • Loading branch information
aoapc-book committed Jul 13, 2014
1 parent 5f062f3 commit f1d4608
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ Chapter 10: 29/29

Chapter 11: 15/15

Chapter 12: 0/37
Chapter 12: 1/37
45 changes: 45 additions & 0 deletions ch12/UVa12538_rope.cpp
Original file line number Diff line number Diff line change
@@ -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<cstdio>
#include<iostream>
#include<ext/rope>
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;
}
2 changes: 1 addition & 1 deletion ch12/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 2 additions & 8 deletions ch7/UVa1601.cpp
Original file line number Diff line number Diff line change
@@ -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<cstdio>
#include<cstring>
#include<cctype>
Expand All @@ -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;
}
Expand Down

0 comments on commit f1d4608

Please sign in to comment.