diff options
| author | KunoiSayami <[email protected]> | 2022-08-07 02:36:03 +0800 |
|---|---|---|
| committer | KunoiSayami <[email protected]> | 2022-08-07 02:36:03 +0800 |
| commit | d889a91c7665b13c3b12b5ae96ae60cb79276d7b (patch) | |
| tree | a45c49704d279048eab019a6f480073f804c4b3e /normal_distribution.cpp | |
| parent | 4d657d308ccc01701afefed6723d7610f0c5ce1b (diff) | |
feat: Implement expt_0802 binary search
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'normal_distribution.cpp')
| -rw-r--r-- | normal_distribution.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/normal_distribution.cpp b/normal_distribution.cpp index 72f914c..e9c646f 100644 --- a/normal_distribution.cpp +++ b/normal_distribution.cpp @@ -5,8 +5,45 @@ #include <set> #include <vector> +inline void +store_into_vector(unsigned long long value, unsigned long long &max_value, + unsigned long long &min_value, + std::vector<unsigned long long> &population_vector) { + if (max_value < value) { + max_value = value; + } + if (min_value > value) { + min_value = value; + } + population_vector.push_back(value); +} + +void checkFileValid(const std::string &name, size_t length) { + + std::vector<unsigned long long> vector; + unsigned long long max_value = 0, min_value = 0xfffffffffffff; + FILE *file = fopen(name.c_str(), "r"); + assert(file); + for (long long i; fscanf(file, "%lld ", &i) != EOF; + store_into_vector(i, max_value, min_value, vector)) + ; + ; + fclose(file); + + vector.resize(length); + for (auto element : vector) { + assert(element != max_value); + assert(element != min_value); + } +} + int main(int argc, char const *argv[]) { + if (argc == 3) { + checkFileValid(argv[1], std::stol(argv[2])); + return 0; + } + std::random_device randomDevice; std::mt19937 randomEngine(randomDevice()); std::normal_distribution<long double> normalDistribution(2147483648, @@ -35,7 +72,6 @@ int main(int argc, char const *argv[]) { auto ret = set.insert(element); if (ret.second) { vector.push_back(element); - // TODO: add offset // printf("%lld\n", element); } } |
