HDU 6288 缺失的數據範圍

題目

思路簡單,wa題無數遍,哭了

對了個拍,發現log2不可以用log來求,因爲不能保證精度,預處理了2的倍數用二分找了。

 

#include<iostream>
#include<stdio.h> 
#include<algorithm>
#include<string.h>
#include<vector>
#include<set>
#include<math.h>
#include<queue>
#include<map>
#include<stack>
#define go(i,a,b) for (int (i)=(a);(i)<=(b);(i)++)
#define ll unsigned long long
using namespace std;
vector<ll>pow2;
void init(){
	pow2.push_back(1);
	go(i,1,63){
		pow2.push_back(pow2[i-1]*2);
	}
}
bool check(ll x, ll a, ll b, ll k){
	ll tmp=1;
	go(i,1,a){
		if (tmp<=k/x) tmp*=x;
		else return false;
	}
	ll y=lower_bound(pow2.begin(),pow2.end(),x)-pow2.begin();
	//cout<<y<<endl;
	if (y==0) return true;
	go(i,1,b){
		if (tmp<=k/y) tmp*=y;
		else return false;
	}
	//cout<<tmp<<endl;
	return true;
}

ll find(ll a, ll b, ll k){
	ll l=1,r=1000000000000000000LL;
	while (l!=r){
		ll m=(l+r)/2+1;
		//cout<<m<<" "<<check(m,a,b,k)<<endl; 
		if (check(m,a,b,k)) l=m;
		else r=m-1;
	}
	return l;
}

int main(){
	init();
	int T;
	ll a,b,k;
	scanf("%d",&T);
	while (T--){
		scanf("%llu%llu%llu",&a,&b,&k);
		//cout<<a<<b<<k;
		ll ans=find(a,b,k);
		printf("%llu\n",ans);
	} 
}


/*
對拍出錯的樣例
1
1 5 71700000000033863 

*/ 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章