题意:有N件湿的衣服,一台烘干机。每件衣服有一个湿度值。每秒会减一,如果用烘干机,每秒会减k。问最少多久可以晒完。

题解:二分。首先时间越长越容易晒完。

    其次判定函数可以这样给出:对于答案 X,每一个湿度大于X的衣服都要被烘干。所以可以直接统计烘干机被用的总时间,如果其大于X则返回0.

    注意向下取整细节。

#define _CRT_SECURE_NO_WARNINGS
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<string>
#include<stack>
#include<ctime>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<sstream>
#include<iostream>
#include<functional>
#include<algorithm>
#include<memory.h>
//#define INF 0x3f3f3f3f
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
#define mmm(a,b) memset(a,b,sizeof(a))
//std::ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void smain();
#define ONLINE_JUDGE
int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
smain();
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return ;
}
const int maxn = 1e5 + ;
int a[maxn];
int n, k;
int l, r, mid;
bool check(int x) {
int now = ;//time for radiator
rep(i, , n) {
if (a[i] > x) {
now += (a[i] - x - ) / (k - ) + ;//k-1&&ceiling/consider integer
if (now > x)return ;
} }
return ;
}
void Run() {
l = , r = ;
r = *max_element(a + , a + + n);
if (k == ) { cout << r<<endl; }
else {
while (l <= r) {
mid = l + r >>;
if (check(mid))r = mid - ;
else l = mid + ; }
cout << l << endl;
}
} void smain() { cin >> n;
rep(i, , n)cin >> a[i];
cin >> k; Run(); }

Drying POJ - 3104 二分 最优的更多相关文章

  1. poj 3104 二分

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12568   Accepted: 3243 Descripti ...

  2. Drying POJ - 3104

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

  3. Divide and conquer:Drying(POJ 3104)

    烘干衣服 题目大意:主人公有一个烘干机,但是一次只能烘干一件衣服,每分钟失水k个单位的水量,自然烘干每分钟失水1个单位的水量(在烘干机不算自然烘干的那一个单位的水量),问你最少需要多长时间烘干衣服? ...

  4. POJ 3104 Drying [二分 有坑点 好题]

    传送门 表示又是神题一道 Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9327   Accepted: 23 ...

  5. POJ - 2018 二分+单调子段和

    依然是学习分析方法的一道题 求一个长度为n的序列中的一个平均值最大且长度不小于L的子段,输出最大平均值 最值问题可二分,从而转变为判定性问题:是否存在长度大于等于L且平均值大于等于mid的字段和 每个 ...

  6. POJ 3104 Drying(二分答案)

    题目链接:http://poj.org/problem?id=3104                                                                  ...

  7. POJ 3104 Drying 二分

    http://poj.org/problem?id=3104 题目大意: 有n件衣服,每件有ai的水,自然风干每分钟少1,而烘干每分钟少k.求所有弄干的最短时间. 思路: 注意烘干时候没有自然风干. ...

  8. POJ 3104 Drying(二分答案)

    [题目链接] http://poj.org/problem?id=3104 [题目大意] 给出n件需要干燥的衣服,烘干机能够每秒干燥k水分, 不在烘干的衣服本身每秒能干燥1水分 求出最少需要干燥的时间 ...

  9. poj 3104 Drying(二分查找)

    题目链接:http://poj.org/problem?id=3104 Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissio ...

随机推荐

  1. java this 子类调父类,父类再调用子类已覆盖的方法及属性(又一次理解)

    之前一直以为 this关键字 是指调用者对象,但是这次才真正理解,this代表当前对象,但是指向调用者对象,其实就是多态的用法,如下所示:B 继承了 A,在B 中调用A类的方法,在A 中用this 访 ...

  2. Centos6.4 编译安装 nginx php

    一. 准备依赖库 安装make: yum -y install gcc automake autoconf libtool make 安装g++: yum install gcc gcc-c++ 二. ...

  3. ubuntu下使用golang、qml与ubuntu sdk开发桌面应用 (简单示例)

    找了很长时间go的gui库,试了gtk,准备试qt的时候发现了这个qml库,试了下很好用. ##准备工作 **1.Go 1.2RC1** go的版本应该不能低于这个,我是在1.2RC发布当天升级后发现 ...

  4. 法线从object space到eye space的转换((normal matrix)

    对于顶点来说,从object Space转换到eye space, 使用model-view矩阵就好了.那么顶点的法线是否也可以直接使用model-view矩阵转化? 通常情况下是不行的. 如下两张图 ...

  5. SmileyCount.java笑脸加法程序代写(QQ:928900200)

    SmileyCount.java 1/4Java Programming 2014Course Code: EBU4201Mini ProjectTask 1 [30 marks]SmileyCoun ...

  6. .NET Memory Allocation Profiling with Visual Studio 2012

    .NET Memory Allocation Profiling with Visual Studio 2012 This post was written by Stephen Toub, a fr ...

  7. Centos7 中lvs DR配置

    服务器主机: 10.200.3.100       DirectServer 10.200.3.99         RealServer1 10.200.3.101 RealServer2 10.2 ...

  8. vue项目在安卓低版本机显示空白原因

    vue项目在安卓低版本机显示空白原因: 可能的原因一: 查看安卓debug,报错,可能有箭头函数语法错误,或者其他语法问题,那可能是ES6语法问题. 这时候需要安装babel-pollyfill. 网 ...

  9. python 切片获取list、tuple中的元素

    #-*- coding:UTF-8 -*- L=[] n=6 r=[1,2,3,4,5,6] for i in range(n): L.append(r[i]) print L # =>[1, ...

  10. [PGM] Temporal Models

    这里的一些东西只是将过去已有的东西用PGM解释了一遍,但优势还是明显的,对整体认识有帮助. Video: https://www.youtube.com/watch?v=ogs4Oj8KahQ& ...