Divide and conquer:Drying(POJ 3104)

题目大意:主人公有一个烘干机,但是一次只能烘干一件衣服,每分钟失水k个单位的水量,自然烘干每分钟失水1个单位的水量(在烘干机不算自然烘干的那一个单位的水量),问你最少需要多长时间烘干衣服?
简单来说题目就是要:时间允许的情况下让时间最小,时间可以无限大,这题就是“最小化最大值”,二分法
#include <iostream>
#include <functional>
#include <algorithm> using namespace std; static int clothes[]; void Search(const int, const int);
bool judge(const long long, const int, const int);
int fcmop(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
} int main(void)//在时间允许的情况下让值最小(最小化最大值)
{
int sum_clothes, re; while (~scanf("%d", &sum_clothes))
{
for (int i = ; i < sum_clothes; i++)
scanf("%d", &clothes[i]);
scanf("%d", &re);
qsort(clothes, sum_clothes, sizeof(int), fcmop);
if (re == )
printf("%d\n", clothes[sum_clothes - ]);//注意一定不要出现0的情况
else
Search(sum_clothes, re);
}
return ;
} void Search(const int sum_clothes, const int re)
{
long long lb = , rb = (long long)10e+ + , mid; while (rb - lb > )
{
mid = (rb + lb) / ;
if (judge(mid, sum_clothes, re)) rb = mid;
else lb = mid;
}
printf("%lld\n", rb);
} bool judge(const long long times, const int sum_clothes, const int re)
{
long long use_time_now, use_sum = ;
int i; for (i = ; i < sum_clothes && clothes[i] <= times; i++); for (; i < sum_clothes; i++)
{
use_time_now = (clothes[i] - times + re - - ) / (re - );//向上取整,要先-1
use_sum += use_time_now;
if (use_sum > times)
return false;
}
return true;
}
Divide and conquer:Drying(POJ 3104)的更多相关文章
- Drying POJ - 3104
It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She ...
- Divide and conquer:Sumsets(POJ 2549)
数集 题目大意:给定一些数的集合,要你求出集合中满足a+b+c=d的最大的d(每个数只能用一次) 这题有两种解法, 第一种就是对分,把a+b的和先求出来,然后再枚举d-c,枚举的时候输入按照降序搜索就 ...
- Divide and conquer:Subset(POJ 3977)
子序列 题目大意:给定一串数字序列,要你从中挑一定个数的数字使这些数字和绝对值最小,求出最小组合数 题目的数字最多35个,一看就是要数字枚举了,但是如果直接枚举,复杂度就是O(2^35)了,显然行不通 ...
- Divide and conquer:Showstopper(POJ 3484)
Showstopper 题目大意:数据挖掘是一项很困难的事情,现在要你在一大堆数据中找出某个数重复奇数次的数(有且仅有一个),而且要你找出重复的次数. 其实我一开始是没读懂题意的...主要是我理解错o ...
- Divide and conquer:Garland(POJ 1759)
挂彩灯 题目大意:就是要布场的时候需要挂彩灯,彩灯挂的高度满足: H1 = A Hi = (Hi-1 + Hi+1)/2 - 1, for all 1 < i < N HN = B Hi ...
- Divide and conquer:Matrix(POJ 3685)
矩阵 题目大意:矩阵里面的元素按i*i + 100000 * i + j*j - 100000 * j + i*j填充(i是行,j是列),求最小的M个数 这一题要用到两次二分,实在是二分法的经典,主要 ...
- Divide and conquer:Median(POJ 3579)
快速求两数距离的中值 题目大意:给你一个很大的数组,要你求两个数之间的距离的中值 二分法常规题,一个pos位就搞定的事情 #include <iostream> #include ...
- Drying POJ - 3104 二分 最优
题意:有N件湿的衣服,一台烘干机.每件衣服有一个湿度值.每秒会减一,如果用烘干机,每秒会减k.问最少多久可以晒完. 题解:二分.首先时间越长越容易晒完. 其次判定函数可以这样给出:对于答案 X,每一个 ...
- [LeetCode] 236. Lowest Common Ancestor of a Binary Tree_ Medium tag: DFS, Divide and conquer
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...
随机推荐
- oracle中substr与instr
在oracle中,可以使用instr函数对某个字符串进行判断,判断其是否含有指定的字符.在一个字符串中查找指定的字符,返回被查找到的指定字符的位置. 语法: Instr(sourceString,de ...
- [译]Mongoose指南 - 验证
开始前记住下面几点 Validation定义在SchemaType中 Validation是一个内部的中间件 当document要save前会发生验证 验证不会发生在空值上 除非对应的字段加上了 re ...
- JVM执行引擎总结(读《深入理解JVM》) 早期编译优化 DCE for java
execution engine: 运行时栈current stack frame主要保存了 local variable table, operand stack, dynamic linking, ...
- 学习(主题或切入点)checklist1
业务+技术+架构+运维+管理 技术学习:http://www.runoob.com/mongodb/mongodb-query.html 一.技术篇补充学习列表 1,mongodb(o) 2,red ...
- 1.交通聚类:编辑距离 (Levenshtein距离)Java实现
1.最近工作中要实现用户车辆的行驶路线的聚类,由于所给的数据只有用户一天中交通卡口所监视的卡口名称 :即青岛路-威海路-济阳路 . 要通过聚类实现车辆路线的规律分析,首先要解决的是相似度问题,我们知道 ...
- PHP命名空间入门教程
PHP5.3当中就引入了“命名空间”的概念,一直都没怎么关注和使用,其实学习它也挺简单的,看官方的教程就行了: 命名空间概述 定义命名空间 定义子命名空间 在同一个文件中定义多个命名空间 使用命名空间 ...
- git之常用指令
参考:Git教程 - 廖雪峰的官方网站 1.git //linux上检测是否安装git 2.sudo apt-get install git //linux上安装git 3.git config - ...
- PHP Socket实现websocket(四)Select函数
int select(int maxfdp,fd_set *readfds,fd_set *writefds,fd_set *errorfds,struct timeval *timeout); /* ...
- js时间格式化(yy年MM月dd日 hh:mm)
//时间格式化 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, / ...
- MS Project 使用之创建项目信息
1. 我们打开MS Project 2013,创建一个空白文档. 2. 切换“项目”选项卡,点击“项目信息”,设置项目开始时间等信息,项目一般是需要设置开始时间和使用日历的,下面我们分别进行设置 如, ...