diff options
| author | KunoiSayami <[email protected]> | 2022-06-24 15:08:03 +0800 |
|---|---|---|
| committer | KunoiSayami <[email protected]> | 2022-06-24 15:08:03 +0800 |
| commit | 447d7d7a363b53b81cf21a30b6765d9e3501484c (patch) | |
| tree | 35633380b74a7e49f743669d73d44e07a42566b8 | |
| parent | 167ab83b42809d59388c739390193cc6e7e3cbe0 (diff) | |
feat(script): Add experiment3
Signed-off-by: KunoiSayami <[email protected]>
| -rw-r--r-- | CMakeLists.txt | 2 | ||||
| -rw-r--r-- | exp_3.cpp | 54 | ||||
| -rw-r--r-- | normal_distribution.cpp | 4 |
3 files changed, 58 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e249fba..4e3ea0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,3 +65,5 @@ build_different_target(true 1048576 8) add_executable(normal_distribution normal_distribution.cpp) set_target_properties(normal_distribution PROPERTIES LINKER_LANGUAGE CXX) +add_executable(normal_distribution_ex3 exp_3.cpp) +set_target_properties(normal_distribution PROPERTIES LINKER_LANGUAGE CXX) diff --git a/exp_3.cpp b/exp_3.cpp new file mode 100644 index 0000000..4e6f8b0 --- /dev/null +++ b/exp_3.cpp @@ -0,0 +1,54 @@ +#include <algorithm> +#include <cassert> +#include <cstdio> +#include <set> +#include <vector> + +constexpr size_t length = 1048576; + +int main() { + + std::vector<long long> vector1, vector2; + + std::set<long long> set1, set2; + + FILE *file = fopen("normal_distribution.txt", "r"); + for (long long i; fscanf(file, "%lld ", &i) != EOF; + vector1.push_back(i), set1.insert(i)) + ; + fclose(file); + + assert(vector1.size() == set1.size()); + assert(vector1.size() == length); + + auto it = vector1.begin(); + for (int i = 1; i <= 1000; i++) { + auto element = *it; + auto ret = set2.insert(element); + if (ret.second) { + vector2.push_back(element); + // printf("%lld\n", element); + } + it++; + } + + assert(vector2.size() == 1000); + + auto it2 = set2.begin(); + int cnt = 0; + for (long long it1 : set1) { + while (it1 > *it2 && it2 != set2.end()) + it2++, cnt++; + // printf("%d ", cnt); + } + + it2 = set1.begin(); + cnt = 0; + for (long long it1 : set2) { + while (it1 > *it2 && it2 != set1.end()) + it2++, cnt++; + printf("%d ", cnt); + } + puts(""); + return 0; +}
\ No newline at end of file diff --git a/normal_distribution.cpp b/normal_distribution.cpp index c320ce4..c965d2a 100644 --- a/normal_distribution.cpp +++ b/normal_distribution.cpp @@ -11,8 +11,8 @@ int main() { std::random_device randomDevice; std::mt19937 randomEngine(randomDevice()); - std::normal_distribution<long double> normalDistribution(2147483647, - 2147483647); + std::normal_distribution<long double> normalDistribution(2147483648, + 2147483648); std::set<long long> set; |
