poj 3232 Accelerator
http://poj.org/problem?id=3232
题意:有一个含有n辆车的车队,当前距离终点的距离已知,有m个加速器,每个加速器在一个时刻只能给一辆车用,一旦使用就会使得其速度由1变成k,加速器可以重复使用,问最快所有车辆到达终点的时间。
思路:二分枚举所需的最短时间。
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 300000
#define ll long long
using namespace std; ll t,n,m,k;
ll a[maxn]; bool ok(ll c)
{
ll cnt=,x=c*m;
for(int i=; i<n; i++)
{
if(a[i]<=c) continue;
if((a[i]-c)%(k-)==)
cnt=((a[i]-c)/(k-));
else
cnt=((a[i]-c)/(k-))+;
if(cnt>c) return false;
x-=cnt;
if(x<) return false;
}
return true;
} int main()
{
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&n);
ll max1=;
for(int i=; i<n; i++)
{
scanf("%lld",&a[i]);
max1=max(max1,a[i]);
}
scanf("%lld%lld",&m,&k);
ll l=,r=max1;
if(k==)
{
printf("%lld\n",max1);
continue;
}
int mid;
while(l<r)
{
mid=(l+r)>>;
if(ok(mid))
{
r=mid;
}
else l=mid+;
}
printf("%lld\n",l);
}
return ;
}
poj 3232 Accelerator的更多相关文章
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- 安卓开发24:FrameLayout布局
FrameLayout布局 FrameLayout是五大布局中最简单的一个布局.FrameLayout布局中的元素会根据先后顺序重叠起来.利用FrameLayout布局元素重叠的特性,我们一般可以做一 ...
- sql server 判断相同值的数据
举个栗子, 求出相同作者的书 select * from [books] where author in (select author from [books] group by author ha ...
- Maven assembly插件输出文件乱码问题
使用Maven的<artifactId>maven-assembly-plugin</artifactId>插件导致输出的XML配置文件源文件的中文注释变成乱码,排查了多个地方 ...
- 四种方案解决ScrollView嵌套ListView问题[转]
http://bbs.anzhuo.cn/thread-982250-1-1.html 以下文章转自@安卓泡面 在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多 ...
- ViewPager禁止滑动以及它与内层滑动控件水平方向上事件冲突的解决方法
一.上图 二.场景描写叙述 最近在做项目的时候.遇到一个怪异的需求,描写叙述例如以下: 1.ViewPager中嵌套3个View,当从View1滑动到View2时禁止ViewPager的滑动事件. 2 ...
- CI框架源代码阅读笔记5 基准測试 BenchMark.php
上一篇博客(CI框架源代码阅读笔记4 引导文件CodeIgniter.php)中.我们已经看到:CI中核心流程的核心功能都是由不同的组件来完毕的.这些组件类似于一个一个单独的模块,不同的模块完毕不同的 ...
- iOS8新特性之基于地理位置的消息通知UILocalNotification
苹果在WWDC2014上正式公布了全新的iOS8操作系统. 界面上iOS8与iOS7相比变化不大,只是在功能方面进行了完好. ...
- Robotium--takeScreenshot(截图)
在Robotium中,截图的方法时调用takeScreenshot(). 但有使用你会发现明明代码里调用了solo.takeScreenshot(),但却没有截图成功,那是因为被测试的应用没有SD卡的 ...
- myqltransactionRollbackexception deadlock found when trying to get lock
linux 下远程连接mysq 命令: mysql -h "1.0.0.1" -u username -p 1 获 取锁等待情况 可以通过检查 table_locks_waited ...
- 彻底卸载MYSQL,windows版
转自:http://blog.csdn.net/jasonandwho/article/details/7451310 网上搜的总结帖,直接贴过来的... 由于安装MySQL的时候,疏忽没有选择底层编 ...