Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include<limits>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- struct Bucket{
- float left;
- float right;
- Bucket():left(0), right(1) {}
- bool isWet() {
- return left - right > 1e-5;
- }
- void update(float L, float R) {
- if (L <= 0.0) left = max(left, R);
- if (R >= 1.0) right = min(right, L);
- }
- };
- void simulate() {
- int N = 100;
- int wet_num = 0;
- Bucket arr[100];
- int num = 0;
- while(wet_num < 100) {
- num += 1;
- float x = rand() * 1.0 / INT_MAX * 100;
- int right = min(99, (int)(x + 0.5));
- int left = (int) (x -0.5);
- if (!arr[left].isWet()) {
- arr[left].update(x - 0.5 - left, x - left + 0.5);
- wet_num+= arr[left].isWet();
- }
- if (!arr[right].isWet()) {
- arr[right].update(x - right - 0.5, x - right + 0.5);
- wet_num += arr[right].isWet();
- }
- }
- cout << num << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement