题意:有四个小偷要偷巧克力,每个小偷偷的巧克力是前一个小偷的k倍。例:a,ak,ak^2,ak^3。然后给出你小偷头巧克力的方案数,问:符合条件的条件下,背包中巧克力量最大值最小是多少。
分析:最大值最小。所以二分n。
1 /************************************************ 2 Author :DarkTong 3 Created Time :2016/7/7 17:06:12 4 File Name :C.cpp 5 *************************************************/ 6 7 #include <cstdio> 8 #include <cstring> 9 #include <iostream> 10 #include <algorithm> 11 #include <vector> 12 #include <queue> 13 #include <set> 14 #include <map> 15 #include <string> 16 #include <cmath> 17 #include <cstdlib> 18 #include <ctime> 19 20 #define INF 0x3f3f3f3f 21 #define esp 1e-9 22 typedef long long ll; 23 using namespace std; 24 ll m; 25 ll Check(ll x) 26 { 27 ll sum=0; 28 for(ll i=2;;++i) 29 { 30 if(x<i*i*i) break; 31 sum+=x/(i*i*i); 32 } 33 return sum; 34 } 35 ll BS() 36 { 37 ll L=0,R=0x7fffffffffffffff; 38 ll t, mid; 39 while(L<R) 40 { 41 mid =(L+R+1)/2; 42 t = Check(mid); 43 // cout<<"t:"<<t<<" L:"<<L<<" R:"<<R<<endl; 44 if(t==m) break; 45 else if(t>m) R=mid-1; 46 else L=mid+1; 47 } 48 if(t==m) return mid; 49 else return -1; 50 } 51 void solve(ll x) 52 { 53 //< cout<<"x:"<<x<<endl; 54 if(x==-1) puts("-1"); 55 else 56 { 57 ll ma=0; 58 for(ll i=2;;++i) 59 { 60 if(x<i*i*i) break; 61 ma = max(ma, (x/(i*i*i)*i*i*i)); 62 } 63 cout<<ma<<endl; 64 } 65 } 66 67 68 int main() 69 { 70 //freopen("in.txt","r",stdin); 71 //freopen("out.txt","w",stdout); 72 scanf("%lld", &m); 73 solve(BS()); 74 return 0; 75 }
时间: 2024-10-03 03:12:52