Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://codeforces.com/problemset/problem/676/B
- //Pyramid of Glasses
- #include <bits/stdc++.h>
- using namespace std;
- int left_glass_pos(int n, const int arr[], const int h)
- {
- int row;
- for(int i = 0; i < h; ++i)
- {
- if(arr[i] >= n)
- {
- row = i;
- break;
- }
- }
- return (n + row + 1);
- }
- void recur(float qnty_arr[], float t, int glass, const int arr[], const int h)
- {
- //cout << "glass " << glass << ", t "
- qnty_arr[glass] += t;
- if(glass >= arr[h-1] - h + 1)
- {
- }
- else{
- if(qnty_arr[glass] > 1.0)
- {
- float overflow = qnty_arr[glass] - 1.0;
- int left_pos = left_glass_pos(glass, arr, h);
- recur(qnty_arr, overflow/2, left_pos, arr, h);
- recur(qnty_arr, overflow/2, left_pos+1, arr, h);
- qnty_arr[glass] = 1.0;
- }
- }
- }
- int main()
- {
- int h, t;
- cin >> h >> t;
- int arr[h];
- arr[0] = 0;
- for(int i = 1; i < h; i++)
- arr[i] = arr[i-1] + i + 1;
- float qnty_arr[arr[h-1]+1] = {0.0};
- recur(qnty_arr, t, 0, arr, h);
- int c = 0;
- for(int i = 0; i <= arr[h-1]; i++)
- {
- if(qnty_arr[i] >= 1.0)
- {
- c++;
- }
- }
- cout << c;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment