Poj 3104 drying (Binary)

Source: Internet
Author: User
/* Set a binary value to mid: 1. Dry clothes with an AI value less than or equal to mid; 2. For a dress whose AI value is greater than the mid value, the minimum time is to use a machine for a period of time and dry it for a period of time. Set these two periods to X1 and X2 respectively, so there is mid = X1 + X2, AI <= K * X1 + X2, solve x1> = (AI-mid)/(k-1), SO (AI-mid) /(k-1) rounded up is the minimum time of the dress. */# Include <stdio. h> # include <string. h> # include <algorithm> # include <stdlib. h> # include <math. h> using namespace STD; int A [100010]; int N, K; int check (int x) {int COT = 0; // drying time for (INT I = 0; I <n; I ++) {if (a [I] <= x) // blow dry continue; cot + = (INT) Ceil (double) (A [I]-x)/(k-1); // rounded up if (COT> X) return false;} return true;} int main () {int I, Cot, count; char s [25]; while (~ Scanf ("% d", & N) {for (I = 0; I <n; I ++) scanf ("% d", & A [I]); scanf ("% d", & K); sort (A, A + n); COT = 0; Count = 0; int L = 0; int r = A [n-1]; If (K! = 1) {While (L <= r) {int mid = (L + r)/2; If (check (MID) r = mid-1; elsel = Mid + 1;} printf ("% d \ n", L);} elseprintf ("% d \ n", a [n-1]);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.