bashNewbie's blog

By bashNewbie, history, 3 years ago, In English

Hi,

Could someone help me out with this problem?

1578E - Easy Scheduling

137851418

#include <bits/stdc++.h>
using namespace std;

#define fast_io ios::sync_with_stdio(false),cin.tie(0)
typedef long long ll;

ll power2(int n)
{
	ll ans=1;
	for(int i=0;i<n;i++) ans*=2;
	return ans;
}

int main()
{
	fast_io;

	int t;cin>>t;
	while(t--)
	{
		int h,p;cin>>h>>p;

		ll cnt=0,r=1,nodes=power2(h)-1;
		while(r<p)
		{
			nodes-=r,cnt++;
			r*=2;
		}
		cnt+=(nodes-1)/p+1;
		cout<<cnt<<"\n";
	}
}

Thanks

EDIT: Pasted code

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
3 years ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

When I click your code link, it tells me "You are not allowed to view the requested page".

UPD: Now I can see it.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by bashNewbie (previous revision, new revision, compare).

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Bump. Please help.

»
3 years ago, # |
Rev. 6   Vote: I like it 0 Vote: I do not like it

nodes -= min(p,r)

EDIT : My code


void testcase(){ int h,p; cin >> h >> p; int ready = 1,ans = 0,tot = (1ll << h) - 1; while(ready < tot){ ans++; tot -= min(p,ready); ready *= 2; } ans += (tot + p - 1) / p; cout << ans << '\n'; }