Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <algorithm>
- #include <fstream>
- int rank(long hash) {
- int r = 1;
- while((hash & 1) == 0 && r <=32) {
- ++r;
- hash >>= 1;
- }
- return r;
- }
- std::pair<uint32_t, uint32_t> get_hashes(const std::string &id, std::hash<std::string> hash) {
- uint32_t mask_left = static_cast<uint32_t>(((1 << 16) - 1) << 16);
- uint32_t mask_right = (1 << 16) - 1;
- uint32_t buf = static_cast<uint32_t>(hash(id));
- return std::make_pair(((buf & mask_left) >> 16), buf & mask_right);
- }
- uint32_t count(std::vector<int> &M) {
- uint32_t m = static_cast<uint32_t>(std::pow(2, 16));
- double alpha = 0.7213 / (1 + (1.079 / m));
- double E = 0;
- for(size_t i = 0; i < M.size(); i++) {
- E += std::pow(2, M[i]);
- }
- E = alpha * m * m * std::pow(E, -1);
- double buf1 = m * 5.0 / 2;
- double buf2 = std::pow(2, 32) / 30.0;
- if (E <= buf1) {
- double zero_count = 0;
- for (size_t i = 0; i < M.size(); i++) {
- if (M[i] == 0) {
- zero_count++;
- }
- }
- if (zero_count != 0) {
- E = m * log(m / zero_count);
- }
- } else if (E > buf2) {
- E = -std::pow(2, 32) * log(1 - (E / std::pow(2, 32)));
- }
- return uint32_t(E);
- }
- int main() {
- std::string line;
- std::hash<std::string> hash;
- std::vector<int> M(static_cast<int>(std::pow(2, 16)), 0);
- // std::ifstream in("input.txt");
- while (std::cin >> line)
- {
- M[get_hashes(line, hash).first] = std::max(M[get_hashes(line, hash).first], __builtin_ffs(get_hashes(line, hash).second));
- }
- uint32_t unique = count(M);
- std::cout << unique << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement