题目大意:有四个小偷,第一个小偷偷a个巧克力,后面几个小偷依次偷a*k,a*k*k,a*k*k*k个巧克力,现在知道小偷有n中偷法,求在这n种偷法中偷得最多的小偷的所偷的最小值。
题目思路:二分查找偷得最多的小偷所偷的数目,并遍历k获取该数目下的方案数。脑子一抽将最右端初始化做了1e15,wa了n多次……
#include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<stdio.h> #include<stdlib.h> #include<queue> #include<math.h> #include<map> #define INF 0xffffffff #define MAX 1e18 #define Temp 1000000000 #define MOD 1000000007 using namespace std; long long n; int ok; long long Check(long long m) { long long ans=0; for(long long i=2;i*i*i<=m;i++) { ans+=(m/(i*i*i)); } return ans; } long long Find() { long long L=1,R=MAX,ans; while(L<=R) { long long Mid=(L+R)/2; long long t =Check(Mid); if(t > n) R=Mid-1; else if(t < n) L=Mid+1; else { ok=1; ans=Mid; R=Mid-1; } } return ans; } int main() { while(scanf("%lld",&n)!=EOF) { ok=0; long long ans=Find(); if(!ok) printf("-1 "); else printf("%lld ",ans); } return 0; }