Earthworms NOIP 2016 (Priority Queue)

85 practices:

Find a maximum priority queue using earthworms, then lazy mark to calculate the length to increase (in addition to others that are cut from the two worms are moved toward the positive direction number, that is equivalent to two to the minus direction of movement some so you can record the cumulative increase of length, there are a few not been added to minus just fine)

#include<queue>
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxm=1e5+7;
int n,m,q,u,v,t;
double p;
int a[maxm];
priority_queue<int > qq;
int grow=0;//总共增长的长度 
int main()
{
 scanf("%d%d%d%d%d%d",&n,&m,&q,&u,&v,&t);
 for(int i=1;i<=n;i++)
 scanf("%d",&a[i]),qq.push(a[i]);
 p=(double)u/v;
 for(int i=1;i<=m;i++)
 {
  int top=qq.top()+grow;
  qq.pop();
  int a1=floor((double)top*p),a2=top-a1;
  grow+=q;
  a1-=grow;
  a2-=grow;// promise next value plus grow itself 
  qq.push (A1), qq.push (A2);
   IF (I% T == 0 ) 
  the printf ( " % D " , Top); 
 } 
 the printf ( " \ n- " );
  for ( int I = . 1 ; I <= n-m +; I ++ ) 
 { 
   int Top = qq.top () + Grow; 
   qq.pop (); 
   IF (I% T == 0 ) 
   { 
        the printf ( " D% " , Top); 
   } 
 } 
 return  0 ;     
}

Bad practice:

Found first is cut into earthworm earthworms than a certain cut off after the earthworm earthworms into large, it can be directly stored in the array.

#include<queue>
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxm=7e6+7;
int n,m,q,u,v,t;
double p;
int a[maxm];
int grow=0;//总共增长的长度 
int now[maxm],cut1[maxm],cut2[maxm];
int h,h1,h2,t0,t1,t2;
int top;
int flag;
bool cmp(int a,int b)
{
 return a>b;    
}
int main()
{
 scanf("%d%d%d%d%d%d",&n,&m,&q,&u,&v,&t);
 for(int i=1;i<=n;i++)
 scanf("%d",&now[i]);
 p=(double)u/(double)v;
 h=h1=h2=1;
 t0=n;
 t1=t2=0;
 sort(now+1,now+n+1,cmp);
 for(int i=1;i<=m;i++)
 {
   top=-2e9+7;
   flag=0;
   if(h<=t0&&now[h]>top) top=now[h],flag=1;
   if(h1<=t1&&cut1[h1]>top) top=cut1[h1],flag=2;
   if(h2<=t2&&cut2[h2]>top) top=cut2[h2],flag=3;
   if(flag==1)
   h++;
   if(flag==2)
   h1++;
   if(flag==3)
   h2++;
   top+=grow;
   int a1=floor((double)top*p),a2=top-a1;
   grow+=q;
   a1-=grow,a2-=grow;
   cut1[++t1]=a1,cut2[++t2]=a2;
   if(i%t==0)
   printf("%d ",top);
 }
 printf("\n");
 for(int i=1;i<=n+m;i++)
 {
      top=-1e9+7;
      flag=0;
     if(now[h]>top&&h<=t0) top=now[h],flag=1;
     if(cut1[h1]>top&&h1<=t1) top=cut1[h1],flag=2;
     if(cut2[h2]>top&&h2<=t2) top=cut2[h2],flag=3;
     if(flag==1)
     h++;
     if(flag==2)
     h1++;
     if(flag==3)
     h2++;
      if(i%t==0)
      {
       printf("%d ",top+grow);    
     }
 }
 return 0;    
}

 

Guess you like

Origin www.cnblogs.com/lihan123/p/11741828.html