From b38d9929f7a015b56b847fde7e83f814f354497e Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Mon, 11 Nov 2019 17:55:52 +0700 Subject: One does not simply do CP well in NNN --- cpptour/weirdo.cc | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 cpptour/weirdo.cc (limited to 'cpptour/weirdo.cc') diff --git a/cpptour/weirdo.cc b/cpptour/weirdo.cc new file mode 100644 index 0000000..f79336c --- /dev/null +++ b/cpptour/weirdo.cc @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include + +using namespace std; + +typedef unordered_map charmap; +typedef set charset; + +constexpr double INF = 1e7; +const charset VOWELS {'a', 'e', 'i', 'o', 'u'}; + +inline size_t +sqr (size_t i) +{ + return i * i; +} + +bool +isvowel (const string& s, size_t i) +{ + try { return VOWELS.count (s.at (i)); } + catch (out_of_range const& e) { return true; } +} + +void +update (const string& s, charmap& x, charmap& f) +{ + charset b; + for (const auto& c : s) + { + f[c]++; + b.insert (c); + } + for (const auto& c : b) + x[c]++; +} + +int +main () +{ + size_t t, l; + string s; + + cin >> t; + while (t--) + { + charmap xa, fa, xb, fb; + cin >> l; + while (l--) + { + cin >> s; + size_t i = s.size (); + bool a = true; + + while (i--) + if (isvowel (s, i - 1) + isvowel (s, i) + isvowel (s, i + 1) < 2) + { + update (s, xb, fb); + a = false; + break; + } + if (a) + update (s, xa, fa); + } + + double sc = 1.0; + for (const auto& p : xa) + sc *= p.second; + for (const auto& p : fa) + sc /= sqr (p.second); + for (const auto& p : xb) + sc /= p.second; + for (const auto& p : fb) + sc *= sqr (p.second); + if (sc > INF) + cout << "Infinity" << endl; + else + cout << sc << endl; + } +} -- cgit 1.4.1