烘干衣服

  题目大意:主人公有一个烘干机,但是一次只能烘干一件衣服,每分钟失水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)的更多相关文章

  1. Drying POJ - 3104

    It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She ...

  2. Divide and conquer:Sumsets(POJ 2549)

    数集 题目大意:给定一些数的集合,要你求出集合中满足a+b+c=d的最大的d(每个数只能用一次) 这题有两种解法, 第一种就是对分,把a+b的和先求出来,然后再枚举d-c,枚举的时候输入按照降序搜索就 ...

  3. Divide and conquer:Subset(POJ 3977)

    子序列 题目大意:给定一串数字序列,要你从中挑一定个数的数字使这些数字和绝对值最小,求出最小组合数 题目的数字最多35个,一看就是要数字枚举了,但是如果直接枚举,复杂度就是O(2^35)了,显然行不通 ...

  4. Divide and conquer:Showstopper(POJ 3484)

    Showstopper 题目大意:数据挖掘是一项很困难的事情,现在要你在一大堆数据中找出某个数重复奇数次的数(有且仅有一个),而且要你找出重复的次数. 其实我一开始是没读懂题意的...主要是我理解错o ...

  5. Divide and conquer:Garland(POJ 1759)

     挂彩灯 题目大意:就是要布场的时候需要挂彩灯,彩灯挂的高度满足: H1 = A Hi = (Hi-1 + Hi+1)/2 - 1, for all 1 < i < N HN = B Hi ...

  6. Divide and conquer:Matrix(POJ 3685)

    矩阵 题目大意:矩阵里面的元素按i*i + 100000 * i + j*j - 100000 * j + i*j填充(i是行,j是列),求最小的M个数 这一题要用到两次二分,实在是二分法的经典,主要 ...

  7. Divide and conquer:Median(POJ 3579)

        快速求两数距离的中值 题目大意:给你一个很大的数组,要你求两个数之间的距离的中值 二分法常规题,一个pos位就搞定的事情 #include <iostream> #include ...

  8. Drying POJ - 3104 二分 最优

    题意:有N件湿的衣服,一台烘干机.每件衣服有一个湿度值.每秒会减一,如果用烘干机,每秒会减k.问最少多久可以晒完. 题解:二分.首先时间越长越容易晒完. 其次判定函数可以这样给出:对于答案 X,每一个 ...

  9. [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 ...

随机推荐

  1. PHP 线程安全与非线程安全版本的区别深入解析

    Windows版的PHP从版本5.2.1开始有Thread Safe(线程安全)和None Thread Safe(NTS,非线程安全)之分,这两者不同在于何处?到底应该用哪种?这里做一个简单的介绍 ...

  2. windows系统添加删除用户命令!

    参考:net   help   usernet   help   group Net   user添加或修改用户帐户或者显示用户帐户信息. 语法net   user   [UserName   [Pa ...

  3. HTML Table导出为Excel的方法

    HTML Table导出为Excel的方法: 直接上源码 <html> <head> <meta http-equiv="Content-Type" ...

  4. 新手学JavaScript都要学什么?

    要从事网页开发,不知从何下手? 会JavaScript语言但是不知道该如何进阶! 最好的方法就是不断地做网页.写代码,不断地看别人的代码,研究别人的代码! 用代码实践JS的每个技巧点:多听多看多问多写 ...

  5. POJ 2151 Check the difficulty of problems

    以前做过的题目了....补集+DP        Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K ...

  6. Windows 7 共享文件夹 给 VirtualBox 中的 Ubuntu 14

    操作步骤如下: 1.打开虚拟机中的 Ubuntu 系统: 2.安装“增强工具” 设备 -> 安装增强工具 3.设置“共享文件夹” 控制 -> 设置 -> 添加共享文件夹 ->  ...

  7. windows server 2008 R2 SP1 安装exchange 2010

    一. 先决条件 若在windows server R2 SP1企业版系统上典型安装exchange server2010 SP3,则需要提前确定一下先决条件 AD域环境,域和林的功能级别必须是wind ...

  8. 关于iframe的滚动条,如何去掉水平滚动条或垂直滚动条

    关于iframe的滚动条,如何去掉水平滚动条或垂直滚动条 关于<iframe>可以通过设置属性scrolling="no" 去掉iframe的两个滚动条. 如何只去掉水 ...

  9. HDU 5074 Hatsune Miku(2014鞍山赛区现场赛E题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5074 解题报告:给出一个长度为n的序列,例如a1,a2,a3,a4......an,然后这个序列的美丽 ...

  10. 【转】Intel RealSense(实感技术)概览

    Intel RealSense(实感技术)概览 1 Reply 版权声明:本文系本站作者自己翻译整理,欢迎转载,但转载请以超链接形式注明文章来源(planckscale.info).作者信息和本声明, ...