[Explanations] NOIP2012

Day1

A Vigenère password

String title, just simulate what

B King game

Title Description

H coincides with National Day, Minister of kings invited to play a game with prizes. First, he let each minister in the left and right hand on top of each wrote an integer king himself was left, each to write an integer on the right hand. Then, let the n ministers in a row, the king stood in the front ranks. After lined up, all the ministers will receive a number of gold coins king reward, the number of coins for each minister were obtained: "row on the left hand in front of all the ministers of the product of the number of" divided "on his right hand number ", then take the results of the whole get down .

The king does not want a minister to get a particularly large prize, so he would like to ask you to help him rearrange the order of the team, so to get the most reward minister, received the reward as little as possible. Note that the king's position has always been in the front ranks.

analysis

Hand written when the multiplication sign +, then hung up,Actually I went to see a solution to a problem, the fight

First owner in accordance with the original sequence lined up, and then to the adjacent two people, we find that the two of them exchanged the order of only two people to change their values, so we greedily the two adjacent maximum a minimum, so get down to the final answer must be the best, probably is the use of a bubble sort of thought

Push can be found in \ (a_i * b_i \) little better on the front, then evaluated directly after the sort, big data, usepythonHigh-precision

Then find yourself a high precision can not write? ?

tags

贪心 高精度

C traveling by car

Title Description

analysis

Well there is progress,AccidentallyThe tag will then catch a glimpse of doubling up,Well good good

Pre-selecting a point from each of the two subsequent.

So we find that we have to ask for a quickly know the answer, you may think of half, then walk a few steps backwards to maintain the energy to where it can multiply

Then go back multiplying record \ (2 ^ i \) wheel (each go A, B one of a) to a point and the distance between them can be a

When queried only need to look up to go a few rounds, then A can no longer see what struggle

Pretreatment:

They want to move forward is to maintain a doubly linked list from, has also put forward a query Fenwick tree add to the mix of inside smaller than its largest and bigger than his minimum code length very odd or two log

Look After a solution to a problem in the front to back is to maintain a doubly linked list, so only need to remove enough (I was a fool, really

tags

倍增 链表

to sum up

In fact, pre-treatment is still very easy to think, the difficulty is the rapid inquiry, multiplication is still very magical na


Day2

A congruence equation

Title Description

On demand \ (X \) congruence equation $ ax \ equiv 1 \ pmod { b} $ smallest positive integer solutions.

analysis

No analysis

European expansion board questions

B by classroom

Title Description

analysis

I did not think to write directly to a segment tree

Later, pay luoguT a point (whether it is constant or comes with a large ugly manMoral decay data)

+ Difference can be bipartite, complexity or not --ei \ (O ((n + m ) logm) \) Well, lying roughly constant small

C epidemic control

Title Description

analysis

Conversion meaning of the questions:

Each army seeking to reach the target position with a minimum value of the maximum

After the meaning of the questions it is easy to think of converting over half,Anyway, I can not think of even half the people

In fact, after half I think it is quite simple:

Consider for a given time, determining whether to meet the requirements of the subject during this time.

We found that, as long as enough time and continue to jump up would certainly be better to stay at the current location, because it can cover more leaves, so, to the highest point can not jump to node 1, can be reached directly jump up the highest point, and then fixed here.

Since a node can not stay, 1 point for us to be considered separately:

Let them stop on the pro-son 1:

  • If the son does not need to cover the military, that all leaf nodes within its sub-tree has been covered, then the army goes out must stay in place better than that, so let it first went 1

  • Otherwise: remember \ (dis \) for the pro-son from 1 to, \ (LEF \) for the army from the pro-son can go far

    • \ (LEF \ Leq 2 * DIS \) : can prove it to stay in this point must go out better than:

      Because once it go out, you need to walk a distance of 1 can also go after the \ (\ geq dis \) troops to cover it. And it came after 1'll go the distance \ (LEF-DIS \ Leq DIS \) , you might as well do a disservice, let \ (\ geq dis \) point to send warmth to others

    • \ (LEF> 2 * DIS \) : In spite of this son away to cover other people

Finally, we get two arrays:

  • After a walk can go down as well as the army can go the distance
  • 1 son needs to be covered and the distance needed

Maintenance greedy enough

Code

LOJ T on the last point, then the read write it preferably it is often passed the card

#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long
const int N=300010;
const int M=600010;
const int MX=25;
using namespace std;

int n,m;
int tag[N];
int top=0,tmp=0;
LL dis[N],hav[N],ned[N],INF=0;
int am[N],dep[N],fa[N][MX];
int edge[M],lst[N],nxt[M],wei[M],t=0;

void read(int &x){
    x=0;char c=getchar();
    for(;c<'0'||c>'9';c=getchar());
    for(;c>='0'&&c<='9';c=getchar())x=(x<<3)+(x<<1)+(c^48);
}

void read(LL &x){
    x=0;char c=getchar();
    for(;c<'0'||c>'9';c=getchar());
    for(;c>='0'&&c<='9';c=getchar())x=(x<<3)+(x<<1)+(c^48);
}

void ADD(int x,int y,int z){
    edge[++t]=y;nxt[t]=lst[x];lst[x]=t;wei[t]=z;
}

void READ(){
    int u,v,w;
    read(n);
    rep(i,1,n-1){
        read(u);read(v);read(w);
        ADD(u,v,w);
        ADD(v,u,w);
    }
    read(m);
    rep(i,1,m)read(am[i]);
}

void SEARCH(int x,int pa){
    dep[x]=dep[pa]+1;
    fa[x][0]=pa;
    for(int i=1;(1<<i)<dep[x];i++)
        fa[x][i]=fa[fa[x][i-1]][i-1];
    for(int r=lst[x];r;r=nxt[r]){
        if(edge[r]==pa)continue;
        dis[edge[r]]=dis[x]+wei[r];
        SEARCH(edge[r],x);
    }
    INF=max(INF,dis[x]);
}

void DFS(int x,int pa){
    if(tag[x]==1)return;
    tag[x]=1;
    int hlp=0;
    for(int r=lst[x];r;r=nxt[r]){
        if(edge[r]==pa)continue;
        DFS(edge[r],x);
        tag[x]&=tag[edge[r]];
        hlp++;
    }
    if(!hlp)tag[x]=0;
}

struct nn{
    int pos;
    LL lef;
}Q[N];

int cmp(nn A,nn B){
    if(A.pos==B.pos)return A.lef<B.lef;
    else return A.pos<B.pos;
}

void UPD(int x,LL lef){
    tep(i,20,0){
        if(lef<dis[x]-dis[fa[x][i]])continue;
        if(dep[fa[x][i]]>1){
            lef-=dis[x]-dis[fa[x][i]];
            x=fa[x][i];
        }
    }
    if(fa[x][0]!=1){
        tag[x]=1;
        return;
    }
    Q[++tmp]=(nn){x,lef};
    return;
}

int CAN(){
    sort(hav+1,hav+top+1);
    sort(ned+1,ned+tmp+1);
    if(top<tmp)return 0;
    int pos=1;
    rep(i,1,top){
        if(pos<=tmp&&ned[pos]<=hav[i])pos++;
    }
    return (pos>tmp);
}

int CHK(LL x){
    top=tmp=0;
    rep(i,1,n)tag[i]=0;
    rep(i,1,m)UPD(am[i],x);
    DFS(1,0);
    sort(Q+1,Q+tmp+1,cmp);
    Q[0].pos=Q[1].pos-1;
    top=0;
    rep(i,1,tmp){
        if(tag[Q[i].pos]||Q[i].pos==Q[i-1].pos){
            hav[++top]=Q[i].lef-dis[Q[i].pos];
            continue;
        }
        if(Q[i].lef<=dis[Q[i].pos]*2)tag[Q[i].pos]=1;
        else hav[++top]=Q[i].lef-dis[Q[i].pos];
    }
    tmp=0;
    for(int r=lst[1];r;r=nxt[r]){
        if(!tag[edge[r]])ned[++tmp]=dis[edge[r]];
    }
    return CAN();
}

LL SOLVE(){
    LL ans=-1;
    LL l=0,r=INF+1000000000;
    while(l<=r){
        LL mid=(l+r)>>1;
        if(CHK(mid))ans=mid,r=mid-1;
        else l=mid+1;
    }
    return ans;
}

int main(){
    READ();
    SEARCH(1,0);
    printf("%lld\n",SOLVE());
    return 0;
}

tags

倍增 二分

to sum up

The most important thing is it intended to convert title

There is a see-half (. · ∀ ·) Techno ゙


Aha finally finished goo,I feel this year's title on half and doubling over and over again so look through to cover half of the test and multiply it really goodWhat nest did not say QuuuuuQ

Monkey friends end Sahua .jpg

2019.10.30

Guess you like

Origin www.cnblogs.com/SCL123/p/11765024.html