From f5dc021ac08fc9bd65b93e271853b8126452fcad Mon Sep 17 00:00:00 2001 From: viniciusrplima <54158629+viniciusrplima@users.noreply.github.com> Date: Mon, 28 Oct 2019 19:55:48 -0300 Subject: [PATCH 1/2] Solution for problem 1097B Solution in C++ language --- codeforces/B/1097B.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 codeforces/B/1097B.cpp diff --git a/codeforces/B/1097B.cpp b/codeforces/B/1097B.cpp new file mode 100644 index 0000000..7c7e292 --- /dev/null +++ b/codeforces/B/1097B.cpp @@ -0,0 +1,50 @@ +// Codeforces 2019 +// Vinicius Rodrigues 15.10.2019 +// Petr and a Combination Lock : Problem 1097B + +#include +#include + +using namespace std; + +void input(vector *vec) +{ + int rots, num; + scanf("%d", &rots); + for(int i = 0; i < rots; i++) + { + scanf("%d", &num); + vec -> push_back(num); + } +} + +int sumWithBitmask(vector nums, int bitmask) +{ + int summation = 0; + for(int i = 0; i < nums.size(); i++) + { + if(bitmask bitand 1 << i) + summation += nums[i]; + else + summation -= nums[i]; + } + return summation; +} + +bool checkIfValid(vector nums) +{ + for(int i = 0; i < 1 << nums.size(); i++) + if(sumWithBitmask(nums, i) % 360 == 0) + return true; + return false; +} + +int main() +{ + vector nums(0); + input(&nums); + if(checkIfValid(nums)) + printf("YES\n"); + else + printf("NO\n"); +} From 51449c219147a53c02f0dfd902d7819ac77e7e95 Mon Sep 17 00:00:00 2001 From: viniciusrplima <54158629+viniciusrplima@users.noreply.github.com> Date: Mon, 28 Oct 2019 19:57:06 -0300 Subject: [PATCH 2/2] Solution for problem 476B Solution in C++ language --- codeforces/B/476B.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 codeforces/B/476B.cpp diff --git a/codeforces/B/476B.cpp b/codeforces/B/476B.cpp new file mode 100644 index 0000000..7c72394 --- /dev/null +++ b/codeforces/B/476B.cpp @@ -0,0 +1,63 @@ +// Codeforces 2019 +// Vinicius Rodrigues 15.10.2019 +// Dreamoon and WiFi : Problem 476B + +#include +#include +#include +#include +#include + +using namespace std; + +double pfat(int n, int k) +{ + if(n == 0 or n == k) return 1; + + double factor = 1.0f; + for(int i = k+1; i <= n; i++) + factor *= i; + + return factor; +} + +double comb(int n, int r) +{ + if(n < r) return 0; + return pfat(n, max(r, n - r)) / pfat(min(r, n - r), 0); +} + +double calcScore(string str) +{ + return count(str.begin(), str.end(), '+') - count(str.begin(), str.end(), '-'); +} + +double calcSpace(string str) +{ + return count(str.begin(), str.end(), '?'); +} + +double calcPositives(float score, int spaces) +{ + return (score + spaces) / 2; +} + +int main() +{ + string send, reach; + cin >> send >> reach; + + double deltaScore = calcScore(send) - calcScore(reach); + double spaces = calcSpace(reach); + double positives = calcPositives(deltaScore, spaces); + double prob; + + if(spaces > 0 and abs(deltaScore) <= spaces and round(positives) == positives) + prob = comb(spaces, positives) * pow(0.5, positives) * pow(0.5, spaces - positives); + else + prob = !deltaScore ? 1.0f : 0.0f; + + + printf("%.12f\n", prob); + return 0; +}