Blue: greedy, monotone queue

Nothing like the examination room.

Apparently nonsense, it should be said that just began to think of some useless.

Decision-making monotonic, so half the answer?

Well, then half the answer. Think about how to check each clam can jump all end?

So each clam can not be left behind ah.

If you are experiencing a stone, you will give priority to the most backward skip to the bird clam clams. (Because can not be left behind ah)

If it's too far away, but to jump, then only clams will never be left behind.

Ah, the idea is quite simple now.

Then we can find this idea seems to be universal. We now get rid of half the answer.

So now the question is no longer whether the check is not left behind, but directly ask how many clams able to in the past.

Continuing with the above ideas, so that the most backward clam try to skip, jump, but abandoned it to go backward to make clam second.

With this idea then you can have fun the AC.

Of course, we need to prove that (I did not see the solution to a problem, my own mouth Hu clams)

For as many clams, 1234 ... are numbered, sorted by where they are currently located

So now suddenly there was a stone is represented by 0: 0 1234 ...

Now use the clams to jump, according to the strategy you just make a jump to get 234 ... 1

Other decision is nothing more than two kinds,

One is the stone clams have ignored it all: This is certainly not good, if you want to ignore it even jump back, then you go down here to knock off the foot after jumping course, it does not deteriorate

Another is to make the jump is not the most backward clam above: you will get (x denotes being stepped sink stone) 12x4 ... 3 like

Compared to the optimal decision, there is a difference is still in the original location of the most backward, but there is a clam under optimal decision a little closer to the top (at least that is no longer the most backward position)

The bird clams on the most backward position may also left behind ever since, so this decision is not excellent.

So maintain a queue, it indicates the position has not yet abandoned clam.

Enumeration of every stone, so the first team to give up the clams can not jump, can jump on the jump, took it out of the first team to change position into the tail.

Because the stone has been sorted, the element must be added to the tail increasing, so the queue comes monotonous.

After all the stones have dance through the queue of clams can not jump to the end to give up.

Finally, there are a few clams queue is a few friends.

Multi measured Empty! The initial position of clams reset to 0!

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n,m,d,l,x[1000005],q[2000005],t,h,T;
 4 int main(){//freopen("blue.in","r",stdin);
 5     scanf("%d",&T);
 6     while(T--){
 7         scanf("%d%d%d%d",&n,&m,&d,&l);
 8         for(int i=1;i<=n;++i)scanf("%d",&x[i]);
 9         h=1;t=m;for(int i=1;i<=m;++i)q[i]=0;
10         for(int i=1;i<=n;++i){
11             while(q[h]+d<x[i]&&h<=t)++h;
12             ++h;q[++t]=x[i];
13         }
14         while(q[h]+d<l&&h<=t)h++;
15         if(t-h==m-1)puts("Excited");
16         else printf("%d\n",t-h+1);
17     }
18 }
Code complexity: 462B

 

Guess you like

Origin www.cnblogs.com/hzoi-DeepinC/p/11331079.html