Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions codeforces/B/1097B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Codeforces 2019
// Vinicius Rodrigues 15.10.2019
// Petr and a Combination Lock : Problem 1097B

#include <stdio.h>
#include <vector>

using namespace std;

void input(vector<int> *vec)
{
int rots, num;
scanf("%d", &rots);
for(int i = 0; i < rots; i++)
{
scanf("%d", &num);
vec -> push_back(num);
}
}

int sumWithBitmask(vector<int> 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<int> nums)
{
for(int i = 0; i < 1 << nums.size(); i++)
if(sumWithBitmask(nums, i) % 360 == 0)
return true;
return false;
}

int main()
{
vector<int> nums(0);
input(&nums);
if(checkIfValid(nums))
printf("YES\n");
else
printf("NO\n");
}
63 changes: 63 additions & 0 deletions codeforces/B/476B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Codeforces 2019
// Vinicius Rodrigues 15.10.2019
// Dreamoon and WiFi : Problem 476B

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stdio.h>

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;
}