Codeforces 689C - Mike and Chocolate Thieves

题意:有四个小偷要偷巧克力,每个小偷偷的巧克力是前一个小偷的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

Codeforces 689C - Mike and Chocolate Thieves的相关文章

CodeForces 689C Mike and Chocolate Thieves (二分)

原题: Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of choco

CodeForces 689C Mike and Chocolate Thieves (二分最大化最小值)

题目并不难,就是比赛的时候没敢去二分,也算是一个告诫,应该敢于思考…… #include<stdio.h> #include<iostream> using namespace std; int main() { long long n; scanf("%I64d",&n); long long left=1,right=1e18,mid,num,m,s; long long ans=-1; while(left<=right) { mid=(le

CodeForces 689C  Mike and Chocolate Thieves

题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412145 题目大意:给定一个数字n,问能不能求得一个最小的整数x,使得在1-x范围内,可以取的n组T*k^3<=x.T,k为任意整数,需要在小于等于x的情况下,凑够n对T,k,使其满足T*k^3<=x.若x存在,则输出x,若x不存在,则输出-1. 解题思路: 先看k=2,(1,2,4,8)/(2,4,8,16)/(3,6,12,24).... k=3,(1

Codeforces 798D Mike and distribution - 贪心

Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, 

CodeForces Round 279 D Chocolate

Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a1 × b1 segments large and the second one is a2 × b2 segments large. Polycarpus wants to give Paras

Codeforces 798D Mike and distribution(贪心或随机化)

题目链接 Mike and distribution 题目意思很简单,给出$a_{i}$和$b_{i}$,我们需要在这$n$个数中挑选最多$n/2+1$个,使得挑选出来的 $p_{1}$,$p_{2}$,$p_{3}$,...,$p_{m}$满足 $a_{p1}+a_{p2}+a_{p3}+...+a_{p_{m}}>a_{1}+a_{2}+a_{3}+...+a_{n}$ $b_{p1}+b_{p2}+b_{p3}+...+b_{p_{m}}>b_{1}+b_{2}+b_{3}+...+b_

codeforces 798C Mike and gcd problem

C.Mike and gcd problem Mike has a sequence A?=?[a1,?a2,?...,?an] of length n. He considers the sequence B?=?[b1,?b2,?...,?bn] beautiful if the gcd of all its elements is bigger than 1, i.e. . Mike wants to change his sequence in order to make it beau

【算法系列学习】codeforces D. Mike and distribution 二维贪心

http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二维的贪心我们可以先让它变成其中一维有序,这样只需要重点考虑另一维,就会简单很多. 首先,对于题目要求的选择元素之和两倍大与所有元素之和,我们可以转化为选择元素之和大于剩下的.然后我们可以将下标按照a从大到小排序.然后选择第一个,之后每两个一组,选择b大的一个,如果n是偶数再选择最后一个. 至于这样写

【算法系列学习】codeforces C. Mike and gcd problem

C. Mike and gcd problem http://www.cnblogs.com/BBBob/p/6746721.html 1 #include<iostream> 2 #include<cstdio> 3 #include<string> 4 #include<cstring> 5 #include<algorithm> 6 #include<cmath> 7 8 using namespace std; 9 const