Mike and Chocolate Thieves(CF #361 Div. 2)
来源:互联网 发布:餐饮软件领域排行 编辑:程序博客网 时间:2024/06/10 01:50
看到这道题时,总感觉题目意思有点奇怪,看样例和最下面的Note可以大概知道它在说什么。
题目大意:四个小偷去偷巧克力,且后一个偷的数量是前一个的 k 倍,而小偷的背包最多可以放 n 块巧克力,问 n 最小为多少。附链接:http://codeforces.com/problemset/problem/689/C。
大体思路:通过样例和Note,再结合描述,可以判断出实际就是求不等式 a*k^3<=n,n的最小值,而题目给的 m 值则是 a、k的组合数,用二分法,可以二分 a 值求 k,也可以二分 k 值求a,然后计算 a 和 k 的组合数。
以下为ac代码:
#include<iostream>using namespace std;int main(){ long long m; cin>>m; //m=1; long long l=1,r=1e20; long long result=-1; while(r>=l){ long long mid=(r+l)/2; long long num=0; for(long long i=2;i*i*i<=mid;i++) num+=mid/(i*i*i); if(num==m) result=mid; if(num>=m) r=mid-1; //整数的话要加1,浮点数就不用 else l=mid+1; //同上 } cout<<result<<endl; return 0;}
1 0
- Mike and Chocolate Thieves(CF #361 Div. 2)
- CF Round #361 (Div. 2) 689C. Mike and Chocolate Thieves
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves
- Codeforces Round #361 (Div. 2) C - Mike and Chocolate Thieves
- Codeforces Round #361 (Div. 2)C. Mike and Chocolate Thieves
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves
- cf#361-C - Mike and Chocolate Thieves-二分
- Mike and Chocolate Thieves
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves (二分法)
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves 二分
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves(二分判断)
- Codeforces #361C. Mike and Chocolate Thieves 二分 数学
- CodeForces-689C.Mike and Chocolate Thieves
- CodeForces 689C Mike and Chocolate Thieves
- codeforces_689C. Mike and Chocolate Thieves(二分)
- Codeforces-689C-Mike and Chocolate Thieves
- 【打CF,学算法——三星级】CodeForces 689C Mike and Chocolate Thieves (二分)
- Codeforces #361 D Mike and Chocolate Thieves(二分+数学)
- 推荐系统中准确率和召回率的理解
- 一.功能测试
- 初入博达
- 【面试题3】二维数组的查找
- Android开发时简单总结
- Mike and Chocolate Thieves(CF #361 Div. 2)
- 基于TensorFlow的多层感知机
- Python学习5-Flask网络框架
- Struts2.5入门之环境设置
- leetcode解题之01#Two Sum Java版
- springboot 修改默认加载的配置文件不为application.properties
- Xss challenges writeup
- javaWEB总结(25):避免表单的重复提交
- PAT 1088