summaryrefslogtreecommitdiff
path: root/other/pbs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/pbs.cpp')
-rw-r--r--other/pbs.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/other/pbs.cpp b/other/pbs.cpp
new file mode 100644
index 0000000..45577e2
--- /dev/null
+++ b/other/pbs.cpp
@@ -0,0 +1,32 @@
+// Q = Anzahl der Anfragen
+// C = Anzahl der Schritte der Operation
+
+vector<vector<int>> focus;
+vector<int> low, high, ans;
+
+ans.assign(Q, C + 1);
+low.assign(Q, 0);
+high.assign(Q, C);
+focus.assign(C + 1, vector<int>());
+for (bool changed = true; changed;) {
+ changed = false;
+ for (int i = 0; i <= C; i++) focus[i].clear();
+ for (int i = 0; i < Q; i++) {
+ if (low[i] > high[i]) continue;
+ focus[(low[i] + high[i]) / 2].pb(i);
+ }
+
+ // Simulation zurücksetzen
+
+ for (int k = 0; k <= C; k++) {
+ // Simulationsschritt
+
+ for (int q : focus[k]) {
+ changed = true;
+ if (/* Eigenschaft schon erfüllt */) {
+ // Antwort updaten
+ high[q] = k - 1;
+ ans[q] = min(ans[q], k);
+ } else {
+ low[q] = k + 1;
+}}}}