[CF752E]Santa Claus and Tangerines(二分答案,dp)
题目链接:http://codeforces.com/contest/752/problem/E
题意:给n个橘子,每个橘子a(i)片,要分给k个人,问每个人最多分多少片。每个橘子每次对半分,偶数的话对半,奇数的话有一半会多一片。
二分答案,拿答案去判断。判断时记录dp(i)为橘子为i片的时候,最多分给多少人。枚举的时候从二分到的答案开始,由当前i的一半相加即可。
#include <bits/stdc++.h>
using namespace std; const int maxn = ;
typedef long long LL;
int n;
LL k;
int a[maxn];
LL dp[maxn]; bool ok(int each) {
memset(dp, , sizeof(dp));
for(int i = each; i < maxn; i++) {
int lo = i / ;
int hi = i - lo;
dp[i] = max(dp[lo] + dp[hi], 1LL);
}
LL ret = ;
for(int i = ; i <= n; i++) ret += dp[a[i]];
return ret >= k;
} int main() {
// freopen("in", "r", stdin);
while(cin >> n >> k) {
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
int ret = -;
int lo = , hi = maxn - ;
while(lo <= hi) {
int mid = (lo + hi) >> ;
if(ok(mid)) {
lo = mid + ;
ret = max(ret, mid);
}
else hi = mid - ;
}
printf("%d\n", ret);
}
return ;
}
[CF752E]Santa Claus and Tangerines(二分答案,dp)的更多相关文章
- E. Santa Claus and Tangerines 二分答案 + 记忆化搜索
http://codeforces.com/contest/752/problem/E 首先有一个东西就是,如果我要检测5,那么14我们认为它能产生2个5. 14 = 7 + 7.但是按照平均分的话, ...
- codeforces 748E Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Santa Claus and Tangerines
Santa Claus and Tangerines 题目链接:http://codeforces.com/contest/752/problem/E 二分 显然直接求答案并不是很容易,于是我们将其转 ...
- E. Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- BZOJ_1044_[HAOI2008]木棍分割_二分答案+DP+单调队列
BZOJ_1044_[HAOI2008]木棍分割_二分答案+DP Description 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个 ...
- 洛谷 P1800 software_NOI导刊2010提高(06)(二分答案+DP检验)
P1800 software_NOI导刊2010提高(06) 标签 二分答案 难度 普及/提高- 题目描述 一个软件开发公司同时要开发两个软件,并且要同时交付给用户,现在公司为了尽快完成这一任务,将每 ...
- Codeforces Round #389 Div.2 E. Santa Claus and Tangerines
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- BZOJ 1044: [HAOI2008]木棍分割(二分答案 + dp)
第一问可以二分答案,然后贪心来判断. 第二问dp, dp[i][j] = sigma(dp[k][j - 1]) (1 <= k <i, sum[i] - sum[k] <= ans ...
随机推荐
- SpringMVC操作指南-MVC-搭建SpringMVC项目结构(基于Java API和注解)
- 用python实现计算1-2*((60-30+(-40/5)*(9-2*5/3+7/3*99/4*2998+10*568/14))-(-4*3)/(16-3*2))类似的公式计算
作业需求: 开发一个简单的python计算器 1.实现加减乘除及拓号优先级解析 2.用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 ...
- java.util.ConcurrentModificationException --map
key:3-key key:/v1.02-key Exception in thread "main" java.util.ConcurrentModificationExcept ...
- PHP数组内容不重复组合排列算法
最近在做ecshop的商品库存模块,分别给一款商品的多个属性组合设置库存,如下图: 一款手机有不同颜色,屏幕尺寸,系统和电量,都要设置不同的库存,如果都要手动选择属性组合,则会耗费很多不必要的时间.假 ...
- 更改android AVD模拟器创建路径位置的方法
打开:计算机-->系统属性-->环境变量—>在“系统变量”那选择“新建”-->变量名为 "ANDROID_SDK_HOME” (注意,必须为这个名字!),然后把变量值 ...
- MWeb 1.4 新功能介绍二:静态博客功能增强
MWeb 比较有特色的是一键生成静态博客功能,然后从 MWeb 最开始规划要做静态博客生成功能时,我就希望 MWeb 的静态博客生成功能在易用的同时,还要有很强大的扩展性. 比如说能自己增加网站公告, ...
- Design and Analysis of Algorithms_Fundamentals of the Analysis of Algorithm Efficiency
I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...
- bzoj3884 上帝与集合的正确用法
a^b mod P=a^(b mod phi(p)) mod p,利用欧拉公式递归做下去. 代码 #pragma comment(linker,"/STACK:1024000000,1024 ...
- NLog配置文件根节点
NLog.config 配置文件信息 <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi ...
- 9月10日,美团网2014校招研发笔试哈尔滨站 1、链表翻转。给出一个链表和一个数k,比如链表1→2→3→4→5→6,k=2,则翻转后2→1→4→3→6→5,若k=3,翻转后3→2→1→6→5→4,若k=4,翻转后4→3→2→1→5→6,用程序实现
// reverselink.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" struct Node{ int num; struct No ...