Woj 1575-signal Generators Monotone Queue optimization DP + blind

Source: Internet
Author: User

Poke here: 1575

Test instructions: N signal transmitters are arranged on a straight line, and each transmitter activated will cause all transmitters within the affected range to be activated. Ask what is the maximum number of transmitters activated after activating any one of the transmitters.

Official problem: May exist in the case of the ring, consider the sort by coordinates I < J < K,j activated K, and then k again activate I. However, this can be translated into a program that directly activates K. So no impact. You can then use DP solution. Dp[i] = max (Dp[j] + 1), Position[j] + r[i] >= position[i], with monotonic queue optimization time complexity is O (n). To the left and right respectively DP again. The maximum value of the last statistic answer.

is also at that time WHU invitational scene did not make out a problem. Back to look at the puzzle, the sense of the puzzle does not take into account all the situation, such as the first signal transmitter on the left side of the two non-affected signal emitter group, and the impact of the first signal transmitter can cover the two lump, at this time if the direct use of monotone queue optimization, You can only select two lump in the signal emitter of the largest lump as a precursor to the formation of the optimal solution (in fact, should both be selected)

I couldn't solve the problem, so I started messing around ... WA a few rounds, the last time before the feeling there is no AC possibility, but the blind code to turn up after the AC got it ...!!!

My practice is: as far as possible to extend the scope of the signal transmitter, the extension of the standard is other completely covered by the signal transmitter of the influence of the range of the signal transmitter (the impact range), so that the left side has two non-affected signal emitter group together as a lump, dp[I] is good to do

1#include"bits/stdc++.h"2 using namespacestd;3 //Dp[i] = max (Dp[j] + 1);4 intN;5 Long Longpos[1000010];6 intr[1000010], r_1[1000010], r_2[1000010];7 intdp_1[1000010], dp_2[1000010];8 9 structTen { One     Long Longindex; A     intvalue; -}q[1000010], TMP; - intfront, rear; the  - intMain () - { -      while(SCANF ("%d", &n)! =EOF) { +         //Initialize -memset (Dp_1,0,sizeof(int) * (N +1)); +memset (dp_2,0,sizeof(int) * (N +1)); A         inti, X; at         //input -         intMostlongradius =0; -          for(i =1; I <= N; ++i) { -scanf"%d%d", &x, &r[i]); -Mostlongradius-=x; -R_2[i] =Max (R[i], Mostlongradius); inMostlongradius =R_2[i]; -Pos[i] = pos[i-1] +x; to         } +Mostlongradius =R[n]; -          for(i = N-1; I >=1; --i) { theMostlongradius-= (Pos[i +1] -pos[i]); *R_1[i] =Max (R[i], Mostlongradius); $Mostlongradius =R_1[i];Panax Notoginseng         } -         //preprocessing a state in which a monotonic queue optimization is not possible because there are no precursors thedp_1[1] =0; +         //start with a pre-active DP AFront = Rear =1; the          for(i =2; I <= N; ++i) { +Tmp.value = Dp_1[i-1]; -Tmp.index = Pos[i-1]; $              for(; Front < rear && Tmp.value > Q[rear-1].value; --rear); $q[rear++] =tmp; -              for(; Front < rear && Pos[i]-tmp.index > R_1[i]; + +front); -             if(Front! =rear) { theDp_1[i] = Q[front].value +1; -             }Wuyi             Else { theDp_1[i] =0; -             } Wu         } -         intres =0; About         //preprocessing a state in which a monotonic queue optimization is not possible because there are no precursors $Dp_2[n] =0; -         //start with a pre-active DP -Front = Rear =1; -          for(i = N-1; I >=1; --i) { ATmp.value = Dp_2[i +1]; +Tmp.index = Pos[i +1]; the              for(; Front < rear && Tmp.value > Q[rear-1].value; --rear); -q[rear++] =tmp; $              for(; Front < rear && tmp.index-pos[i] > R_2[i]; + +front); the             if(Front! =rear) { theDp_2[i] = Q[front].value +1; the             } the             Else { -Dp_2[i] =0; in             } theres = max (res, dp_1[i] + dp_2[i] +1); the         } Aboutprintf"%d\n", res); the     } the}

Woj 1575-signal Generators Monotone Queue optimization DP + blind

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.