Skip to content

Instantly share code, notes, and snippets.

@istupakov
Created December 9, 2016 19:21
Show Gist options
  • Save istupakov/865a2826322f2d352c774bf7e5a2c893 to your computer and use it in GitHub Desktop.
Save istupakov/865a2826322f2d352c774bf7e5a2c893 to your computer and use it in GitHub Desktop.
ACM ICPC NEERC 2016: Problem F. Foreign Postcards
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
std::string a;
getline(std::cin, a);
int n = a.size();
long long c = 0, w = 0;
double f = 0, fs = 0;
for (int i = n - 1; i >= 0; --i) {
if (a[i] == 'C') {
w += n - i;
f = c + fs;
}
else {
c += n - i;
f = w + fs;
}
f /= n - i;
fs += f;
}
cout << setprecision(14) << f << endl;
}
@istupakov
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment