// UVa 11150 - Cola
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
int full = n;
int empty = 2;
int drank = 0;
while (true) {
if (full) {
empty += full;
drank += full;
full = 0;
} else {
int pos_full = empty / 3;
int pos_empty = empty % 3;
if (pos_full + pos_empty < 2 && pos_full > 0) {
pos_full--;
pos_empty += 3;
}
if (full == pos_full && empty == pos_empty)
break;
else {
full = pos_full;
empty = pos_empty;
}
}
}
cout << drank << endl;
}
return 0;
}
No comments:
Post a Comment