当前位置:网站首页>J. Balanced Tree

J. Balanced Tree

2022-06-11 03:29:00 to cling

2022 Jiangsu Collegiate Programming Contest

Solution

 Insert picture description here

 Insert picture description here

 Insert picture description here

 Insert picture description here

Code

#define ll unsigned long long int

ll dfs(ll x, ll a, ll b, ll c)
{
    
	if (x == 0) return 0;
	if (x == 1) return c;
	if (x & 1) return dfs(x >> 1, a * 2 + b, b, c + b);
	else return dfs(x >> 1, a, a + b * 2, c + a);
}
 
int main()
{
    
	IOS;
	int T; cin >> T;
	while (T--)
	{
    
		ll ans = 1;
		ll n; cin >> n;													
		ll c = dfs(n, 1, 0, 0);
		if (c >= 64) ans = 0;
		else ans <<= c;
		cout << ans << endl;
	}
 
 
	return 0;
}
原网站

版权声明
本文为[to cling]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110321474262.html