Codeforces 460C, codeforces460c

Source: Internet
Author: User

Codeforces 460C, codeforces460c

The Code has a detailed explanation, binary simulation is used to find the result, and the greedy choice starts from where to pour the flowers. The principle is that if the flowers need to be watered, the w can use the line segment tree to maintain the line segment, but you can also mark it with a number group. There are always a lot of problems with binary, so writing a lot of output for debugging, jiong

/*************************************** * *********************************> File Name: 460c. cpp> Author: yang> Mail: 826123027@qq.com> Created Time: friday, August 22, 2014, 11:17:43 ************************************* * *********************************/# include <iostream> using namespace std; # include <memory. h> # include <stdio. h> # define N records 5int a [N]; int main () {int n, m, w, memory [N], B [N]; while (cin> n> m> w) {int l = 0x7fffff, r = 0; for (int I = 0; I <n; I ++) {cin> a [I]; if (a [I] <l) l = a [I]; if (a [I]> r) r = a [I];} r + = m; // The longest height while (l <= r) {// No = at the beginning, wa once int tempm = m; int mid = (l + r)> 1; for (int I = 0; I <n; I ++) {B [I] = mid-a [I]; // array B is used to record the number of days required for each flower if (B [I] <= 0) B [I] = 0;} memset (memory, 0, sizeof (memory); // remember when to end w-length watering int index = 0, x = 0; // x indicates the number of days for watering each flower due to the influence of watering the flowers in front. For example, if the number of days for watering the flowers in front is 3, then I + 1, I + 2 flowers get x-day watering flowers for (int I = 0; I <n; I ++) {x + = memory [I]; if (B [I]-x)> 0) {B [I]-= x; tempm-= B [I]; if (tempm <0) {break ;} x + = B [I]; // x can accumulate the number of days for watering from the front. memory [I + w]-= B [I]; // After the length is w, the watering days will be returned.} if (tempm> = 0) l = mid + 1; else r = mid-1 ;} printf ("% d \ n" L-1 );}}





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.