codeforce 689C 【二分】
来源:互联网 发布:淘宝五张宝贝主图规律 编辑:程序博客网 时间:2024/06/05 08:38
题意:
有四个小偷偷巧克力,并且他们偷的数量成等比数列(第一个偷a,第二个偷a*q,第三个偷a*q*q,第四个偷a*q*q*q),每个小偷最多不能偷超过n个巧克力,现在给出他们最多的偷法m,求最小的n。
比如:m=2,两种偷法为(1,2,4,8),(2,4,8,16),所以n最小为16
题解:
对于一个n,我们可以枚举q求解偷法m = ∑n/(i*i*i) (i=1;i*i*i<=n;i++)
所以对于某个n我们可以在O(n^1/3)求解,再二分n,当某个n求解得到的偷法等于m时该n可视为符合要求
#include<iostream>#include <stdio.h>#include <algorithm>#include <math.h>#include<stdlib.h>#include <string.h>#include<queue>#include<set>#include<map>#include<stack>#include<time.h>using namespace std;#define MAX_N 200005#define inf 0x7fffffff#define LL long long#define ull unsigned long long#define mod 1000000007LL INF=9e18;LL cal(LL n){ LL sum = 0; for(LL i=2;i*i*i<=n;i++) sum += (n/(i*i*i)); return sum;}int main(){ LL m; cin >> m; LL low = 0; LL up = INF; LL ans = INF; while(low < up) { LL mid = (low + up) / 2; LL tmp = cal(mid); if(tmp >= m) up = mid; else low = mid + 1; if(tmp == m) ans = mid; } if(ans == INF) cout << -1 << endl; else cout << ans << endl;}
0 0
- codeforce 689C 【二分】
- codeforce 689D 【二分+RMQ】
- Codeforce 734C Anton and Making Potions 枚举+二分
- Codeforce#379C. Anton and Making Potions(二分or贪心)
- 【CodeForce 734C 】Anton and Making Potions (枚举+二分)
- codeforce 738 C Road to Cinema 选车 (二分)
- codeforce 785 C.Anton and Fairy Tale(二分)
- codeforce round412 div2 C sucess rate 数学|二分
- codeforce 551C GukiZ hates Boxes(二分+贪心)
- Codeforce 327D 二分
- codeforce 803-B 二分查找
- CodeForce 237C Primes on Interval(二分+ 素数筛法)
- Codeforce#354C. Vasya and String(前缀和二分or尺取)
- 文章标题 codeforce 812C Sagheer and Nubian Market(二分)
- Codeforce # C. Average Score
- CodeForce 279C
- codeforce 237 C D
- Codeforce C. Barcode
- 杭电1406 完数 java
- 我遇到过的 iOS 面试题(Object-C)
- Linux常用操作-1
- [Leetcode] #110 Balanced Binary Tree
- CodeVS1358棋盘游戏
- codeforce 689C 【二分】
- PAT甲级1026
- 大背包的解决方案
- vim ctags
- 使用Boost库作为网络通信
- poj3469(*最小割模型)
- localeCompare() 方法的使用
- can总线与usb总线比较,那个可靠?
- uvalive7271(A Math Problem) 数位dp