Bzoj 1863: [Zjoi2006]trouble of the Emperor's troubles (two-point answer)

Source: Internet
Author: User

Two-point answer. Then push it from top to bottom to see if the last one can pick up 0 medals that are the same as the first.

-----------------------------------------------------------------------

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 20009;int W[MAXN], MIN[MAXN], MAX[MAXN], N; void init () {scanf ("%d", &n);for (int i = 0; i < N; i++) scanf ("%d", w + i);}bool Check (int x) {if (w[0] + w[n-1] > x) return false;for (int i = 1; i < N; i++)if (w[i-1] + w[i] > x) return false;min[0] = max[0] = w[0];for (int i = 1; i < N; i++) {Max[i] = min (W[i], w[0]-min[i-1]);if (X-w[i-1]-(w[0]-max[i-1]) >= w[i])Min[i] = 0;ElseMin[i] = w[i]-(x-w[i-1]-(w[0]-max[i-1]));}return! MIN[N-1];}int main () {init ();int L = 1, R = 1000000, ans;While (L <= R) {int m = (L + R) >> 1;if (check (m))ans = m, R = m-1;ElseL = m + 1;}printf ("%d\n", ans);return 0;}

-----------------------------------------------------------------------

1863: [Zjoi2006]trouble Emperor's troubles Time Limit:1 Sec Memory Limit:MB
Submit:475 Solved:245
[Submit] [Status] [Discuss] Description

After years of killing, the Qin emperor finally unified China. To ward off foreign aggression, he was preparing to place N generals on the border of the land. Unfortunately, the ambitions of the N generals began to reveal their own wings. They refused to do their debriefing and refused to accept the emperor's decree. The emperor is ready to execute the rude frontier generals in secret. But to prevent the mutiny, he decided to give the generals some medals to win the strategic time for themselves. The generals were delighted to hear that they were about to be awarded a medal, and they said thanks. The first general requires the AI to be decorated in different colors. But these generals are very arrogant, if the two adjacent generals have the same color of the medal they will think the emperor does not respect them, will immediately rebel (the general numbered I and the general numbered i+1 adjacent; because their stationed border can be similar as a circle, so the number 1 and the General number n is also adjacent). The emperor had to meet the demands of every general, but was indignant at their domineering. So the emperor decided to cast as few kinds of medals as possible to meet the demands of these arrogant people. How many colors of medals must he cast at least?

Input

The first line has an integer n (1<=n<=20000). The next n rows are an integer AI for each line, which indicates how many medals the first general requires. (1<=ai<=100000) outputs an integer, which is the minimum number of medals required.

Output

4 2 2) 1 1

Sample Input 4
Sample Outputhint

Source

Two points

Bzoj 1863: [Zjoi2006]trouble of the Emperor's troubles (two-point answer)

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.