sheva
BAN USER@aonecoding Could you please clarify for the above follow up question:
According to ur soln:
The probability of picking a point from Rectangle0 => (area0-1) / area0 [can't pick 0 as total = 0]
The probability of picking a point from Rectangle1 => area1 / (area0 + area1)
The probability of picking a point from Rectangle2 => area2 / (area0 + area1 + area2)
The probability of picking a point from RectangleN => areaN / (area0 + area1 + ... areaN)
So isn't it non-uniform ?
Take two pointers, read and write.
Read points to the next read index
Write points to the next write index
class Ring
{
string buffer;
int n, r, w; // size of ring buffer, read pointer, write pointer
public:
Ring(int _n) : n(_n)
{ r = w = 0; }
string Read(size_t sz)
{
string chunk;
while (r != w && chunk.length() < sz)
{
chunk += buffer[r++];
if (r == n)
r = 0;
}
return chunk;
}
size_t Write(string chunk)
{
int i;
for (i=0; i<chunk.length(); i++)
{
if ((w+1) % n == r)
break;
buffer[w++] = chunk[i];
if (w==n)
w = 0;
}
return i;
}
};
RepVealeJasso, Backend Developer at 247quickbookshelp
I am Veale, Learning and development manager handling the training and professional development of company employees. I love makeup, cats ...
RepMiguelCortez, Accountant at Apache Design
I am a webmaster and a person responsible for maintaining one or more websites. I spend most of my time ...
- sheva August 10, 2017