From c5fcf7179a83ef65c86c6a4a390029149e518649 Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Tue, 5 Oct 2021 21:49:54 +0200 Subject: Duzy commit ze smieciami --- semestr-4/aisd/pracownia1/pracownia1.pdf | Bin 0 -> 55846 bytes semestr-4/aisd/pracownia1/rozw.cpp | 59 +++++++++++++++++++++++++++++++ semestr-4/aisd/pracownia1/rozw2.cpp | 33 +++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 semestr-4/aisd/pracownia1/pracownia1.pdf create mode 100644 semestr-4/aisd/pracownia1/rozw.cpp create mode 100644 semestr-4/aisd/pracownia1/rozw2.cpp (limited to 'semestr-4/aisd/pracownia1') diff --git a/semestr-4/aisd/pracownia1/pracownia1.pdf b/semestr-4/aisd/pracownia1/pracownia1.pdf new file mode 100644 index 0000000..2b99ba4 Binary files /dev/null and b/semestr-4/aisd/pracownia1/pracownia1.pdf differ diff --git a/semestr-4/aisd/pracownia1/rozw.cpp b/semestr-4/aisd/pracownia1/rozw.cpp new file mode 100644 index 0000000..acbd711 --- /dev/null +++ b/semestr-4/aisd/pracownia1/rozw.cpp @@ -0,0 +1,59 @@ +#include +using namespace std; +typedef long long ll; + +vector>> v; +const int MAX_LEN = 85; +int bits[100]; + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(); + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int d, nd; + cin >> d >> nd; + int k = 0; + while (d % 2 == 0) { + d /= 2; + k++; + } + v.push_back({d, {k, nd}}); + } + sort(v.begin(), v.end()); + int result = 0; + + for (int i = 0; i < n; ) { + int h = i; + int d = v[i].first; + while (h < n && v[h].first == d) { + h++; + } + for (int k = 0; k < MAX_LEN; k++) + bits[k] = 0; + for (int j = i; j < h; ++j) { + ll x = (ll)(1LL << v[j].second.first) * (ll)v[j].second.second; + int k = 0; + while (x > 0) { + if (x % 2 == 1) { + bits[k]++; + } + x /= 2; + k++; + } + } + + for (int k = 0; k < MAX_LEN; k++) { + if (bits[k] > 1) { + bits[k + 1] += bits[k]/2; + } + if (bits[k] % 2 == 1) { + result++; + } + } + i = h; + } + + cout << result << "\n"; +} \ No newline at end of file diff --git a/semestr-4/aisd/pracownia1/rozw2.cpp b/semestr-4/aisd/pracownia1/rozw2.cpp new file mode 100644 index 0000000..35fd37e --- /dev/null +++ b/semestr-4/aisd/pracownia1/rozw2.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; +typedef unsigned long long ll; + +vector> v; + +int main() { + int n; + scanf("%d", &n); + for (int i = 0; i < n; i++) { + int d, nd, k = 0; + scanf("%d %d", &d, &nd); + while (d % 2 == 0) { + k++; + d /= 2; + } + v.push_back({d, (ll)(1LL<