c0der
BAN USER
Comments (2)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
struct _ratio {
double sug;
double wtr;
};
void conv_ratio_to_vol(struct _ratio* r, int n) // volume in unit of cups
{
int i;
double denom;
denom = r>sug + r>wtr;
for (i = 0; i < n; i++) {
r[i].sug /= denom;
r[i].wtr /= denom;
}
}
bool find_comb(struct _ratio* v, int n, double sum_sug, double sum_wtr)
{
int ret = false;
if (n = 0) {
return false;
}
// Two Choices for current cup 1. Not Sum it, 2 Sum it
// 1 Dont Sum it
ret = find_comb(v + 1, n  1, sum_sug, sum_wtr);
if (ret) return ret;
// 2 Sum it
sum_wtr += v>wtr;
sum_sug += v>sug;
if (sum_wtr == sum_sug) {
return true;
}
ret = find_comb(v + 1, n  1, sum_sug, sum_wtr);
return ret;
}
bool can_find_one_to_one(struct _ratio* r, int n)
{
conv_ratio_to_vol(r, n);
return find_comb(r, n, 0, 0);
}

c0der
September 12, 2013 Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Open Chat in New Window
Open Chat in New Window
 c0der September 13, 2013