test20190815 NOIP2019 simulation title

100 + 60 + 40 = 200, is behind the two title cards with me very unhappy.

Cube number

[Problem Description]
As a big fan of XX clan, MdZzZZ see their favorite team lost in the semifinals, suddenly disheartened. From looking at the cattle there to grab the high price of tickets to the finals in their hands, MdZzZZ feel to the nest has no meaning, so he decided to jump the "Water Cube." When he was ready to enter the "Water Cube" stadium, an aunt stopped in his way, and had a bit of dialogue:

Aunt: "Young man I think you Yintang black, if I may say so, this is what will be afraid to go to his party eventuality."
MdZzZZ: "Mother do not stop me, I want to dive cubic vent!"
Aunt: "Young man, things to think twice, you know what it is yet the most famous water Cube "?
MdZzZZ:" I do not know ... "
Mother:" this is the most famous water cube 'Cube'! "
MdZzZZ:"? Oh, "
Aunt :.. "Do not worry, listen to me carefully to have 'Cube' is, if a third power of the number, then this number is the number of cubic may be writing is a positive integer, for example, it is the smallest 3-1,8,27 cubic number. "
MdZzZZ:" ...... "
Mother:"! of course, you want to come and go in this water cube, you need to know 'the difference between the number of cubic' '
Mother: "If a number can be written as two cubic the difference in the number, then this number is 'the number of cubic difference', for example, 7 (8-1), 26 (27-1), 19 (27-8) are the cubic difference. If you can not be determined just a few 'number of cubic poor', then you can truly a small world in this carefree when a small fish ... "

And other MdZzZZ not react, to Aunt drifted away, leaving him alone to think carefully over there. So your question now, and you need help MdZzZZ solve this problem. Now, given a number P, MdZzZZ want to know this number is not the number of cubic poor.

Of course, you might have random output some strange things, so there is MdZzZZ T ~ times to ask this question may be too difficult ...... therefore MdZzZZ provisions P is a prime number!

[Input format
into a file called cubicp.in. The first
line of a number of T, T set of data expressed.
Next T lines, each line a number of P.

[] Output format
output file name cubicp.out. T output line for each difference in the number if the number of cubic, output "YES", and otherwise outputs "NO".

Sample 1 [O]
cubicp.in
. 5
2
. 3
. 5
. 7
. 11
cubicp.out
NO
NO
NO
YES
NO

[Agreed with the data size]
for 30% of the data p <= 100.
For 60% of the data p <= 10 ^ 6.
To 100% of the data p <= 10 ^ 12, T <= 100.

noip2018 simulation game cube number 2

\[ p=a^3-b^3=(a-b)(a^2+ab+b^2)\\ \because p \in P\\ \therefore a-b=1,p=a^2+ab+b^2\\ \therefore a^2+a(a-1)+(a-1)^2=p\\ \therefore a=\frac{3+\sqrt{12p-3}}{6} \]

int main(){
    freopen("cubicp.in","r",stdin),freopen("cubicp.out","w",stdout);
    for(int t=read<int>();t--;){
        LL p=read<LL>();
        int a=(3+sqrt(12*p-3))/6;
        puts(p==3LL*a*a-3*a+1?"YES":"NO");
    }
    return 0;
}

Dynamic Programming

[Problem Description]
MdZzZZ after realized the ultimate esoteric life, I decided to go to Tibet purify their souls. While he enjoy the scenery of a sudden there is a large flock of sheep broke into his line of sight.

In this case MdZzZZ thought of a question, the question is this: if a total of n sheep flock, put them in a straight line, and each of the sheep to a standard value. Value is defined as the interval period of this same interval the logarithm of the number. MdZzZZ want to flock into this segment exactly k interval, after calculating the value of these sheep is n and the k value segment interval. MdZzZZ now want the ultimate value of this n sheep and as little as possible.

For example, six sheep were worth 1,1,2,2,3,3, and now they want to cut into 3 sections. MdZzZZ immediately had a good method, into [1], [1,2], [2,3,3], so that only the third section has a value of 1. So these six sheep and value of 1. When MdZzZZ thinking to explore more sheep, he can not help but lost in thought ... then MdZzZZ deeply immersed in the world of thinking inside, and fell asleep.

But good times are always so short, dark days to go immediately. MdZzZZ have to find a hotel before dark and stay. You now need help MdZzZZ solve this problem, and as soon as possible to wake him up. Of course, you must first solve the problem and then wake him up, or MdZzZZ may take up gas has been reluctant to leave.

[Input format
into a file called dp.in.
The first two row number n, k.
Next, a line number n which n represents the number of AI.

[] Output format
output file name dp.out.
A number indicates the answer.

Sample 1 [O]
dp.in
10 2
1 2 1 2 1 2 1 2 1 2
dp.out
. 8

[Agreed with the data size]
for 30% of data n <= 10.
60% of the data for n <= 1000.
To 100% of the data 1 <= n <= 100000,1 < = k <= min (n, 20), 1 <= ai <= n.
Wherein 30% identical data satisfies ai uniformly distributed in all the data.

CF686F Yet Another Minimization Problem

DP write the first equation
\ [f (i, k) = \ min_ {0 \ leq j <i} f (j, k-1) + w (j + 1, i) \]

Since \ (K \) is small, so no need bipartite derivative slope. Consider behind that \ (W \) function, which satisfies the inequality quadrilateral.

This is very intuitive, considering that contain images of ≥ four line segments intersect, you find that not to be counter-example.

Try proof \ (\ FORALL A <B \)
\ [W (A, B +. 1) + W (A +. 1, B) \ GEQ W (A, B) + W (A +. 1, B +. 1) \ ]
transposition give
\ [w (a, b +
1) -w (a, b) \ geq w (a + 1, b + 1) - w (a + 1, b) \] and the following formula considerable difference in \ ([a, b] \ ) and \ ([a + 1, b ] \) to the right to expand the increment of a grid, and it is clear that the size of this relationship.

Since (w \) \ contribution can not be quickly calculated, so the use of range divide and conquer approach .

Solving for the current set interval \ ([L, R & lt] \) , the optimal decision interval \ ([L, R & lt] \) . For the mid-point of the current partition of \ (MID \) , we need to \ ([L, \ min ( R, mid)] \) violence to find optimal decision \ (k \) . Notes from \ (w (l, r) \) to \ (w (l, r + 1) \) or from \ (w (l, r) \) to \ (w (l + 1, r) \ ) can all be done \ (O (1) \) , as long as open a barrel record number of the current interval for each color appears to be all right. The pointer \ (I \) from \ (L \) Move \ (\ min (R, mid ) \) and continue to count \ (F (I) + W (I, MID) \) , eventually found \ (k \) .

Note that when entering the zone solved, we should make sure that \ ([L, l-1 ] \) presence information, so as to ensure that the complexity of divide and conquer.

So we consider the answer to how to deal with the problem before entering the sub-sub-problems. Look subproblems left ( \ ([L,. 1-MID], [L, K] \) ) and apparent current issues \ ([L, l-1 ] \) is the same. We note that in seeking \ (k \) time to \ (w \) and barrels have been modified, then we can direct reduction came back into the left sub-problem.

The right sub-problem? ( \ ([MID +. 1, R & lt], [K, R & lt] \) ) which is to be pretreated \ ([K, MID] \) , and the current is \ ([L, l-1 ] \) . Therefore, we first point pointer from right \ (l-1 \) Move \ (MID \) , and the tub \ (W \) are coupled to, and then from the left point \ (L \) Move \ (K \ ) , buckets and \ (w \) are lost, then into the like. Back time or to restore the \ ([L, L-. 1] \) , since the upper layer to be subsequently used.

Coupled with LaTeX drawing? ? ?

Solving Interval: \ (| \ pretreatment of the gets \ to | l \ frac {\
qquad \ qquad \ qquad \ downarrow ^ {mid} \ qquad \ qquad \ qquad} {} r \) Decision section: \ (L \ {FRAC \ qquad \ qquad \ qquad \ qquad \ downarrow ^ {k} \ qquad \ qquad \ qquad} {} R \)

When the examination was too naive, and bent forward to find \ (w \) is an expression of what look monotonous. I did not expect to see from the meaning ...... In addition, I did not try to directly hit the table. I feel may need to have more skills exam guess.

Time complexity \ (O (NK \ log n-) \) .

co int N=100000+10;
int n,k,a[N],b[N];
LL f[N],g[N];

void solve(int l,int r,int L,int R,LL w){
    if(l>r) return;
    int mid=(l+r)>>1,p=min(mid,R),k=0;
    for(int i=l;i<=mid;++i) w+=b[a[i]]++;
    for(int i=L;i<=p;++i) w-=--b[a[i]],f[mid]>g[i]+w?f[mid]=g[i]+w,k=i:0;
    
    for(int i=l;i<=mid;++i) w-=--b[a[i]];
    for(int i=L;i<=p;++i) w+=b[a[i]]++;
    solve(l,mid-1,L,k,w);
    
    for(int i=L;i<k;++i) w-=--b[a[i]];
    for(int i=l;i<=mid;++i) w+=b[a[i]]++;
    solve(mid+1,r,k,R,w);
    
    for(int i=l;i<=mid;++i) --b[a[i]];
    for(int i=L;i<k;++i) ++b[a[i]];
}
int main(){
    freopen("dp.in","r",stdin),freopen("dp.out","w",stdout);
    read(n),read(k);
    for(int i=1;i<=n;++i)
        g[i]=g[i-1]+b[read(a[i])]++;
    memset(b,0,sizeof b);
    while(k--){
        memset(f,0x3f,sizeof f);
        solve(1,n,1,n,0);
        swap(f,g);
    }
    printf("%lld\n",f[n]);
    return 0;
}

game

[Problem Description]
MdZzZZ recent very upset, because his friends have to play Pokemon Go!, And he has always been dismissive of this type of game, so no one came to him every day to play. So MdZzZZ I want a new game, he proudly named these games guessing game.

Rules of the game is this: There are positive integer n mutually different, MdZzZZ can guess each time period of a minimum range. For example, there must be a certain minimum interval [li, ri].

So he's happy his friend WdZzZZ invited to play this game. So MdZzZZ proud that in this game, he could construct a scheme makes WdZzZZ satisfied until ...... WdZzZZ own guess is contradictory! For example WdZzZZ guess [1,5] The minimum number is 2 [1,6] The minimum value is 3, which is obviously contradictory.

Now you need to help MdZzZZ judgment, many times in WdZzZZ guessing the beginning has been contradictory.

[Input format
into a file called number.in. The first two numbers n and row T,
expressed n digital, LYK guess T times.
Next T lines of three numbers represent li, ri and xi.

[] Output format
output file name number.out. The output of a number indicates how many times appeared contradictory,
if there is a conflict has not output T + 1.

Sample 1 [O]
number.in
20 is. 4
1 10. 7
. 5. 19. 7
. 3. 8 12 is
a 20 is 1

number.out
3

[Agreed with the data size]
for 50% of the data n <= 8, T <= 10.
80% of the data for n <= 1000, T <= 1000.
To 100% of the data 1 <= n, T <= 1000000,1 <= li <= ri <= n, 1 <= xi <= n ( but does not guarantee that all numbers are beginning to 1 ~ n) .

[Hint] recommended reading optimization

ChiTongZ solution to a problem of

Said direct positive solution, the off-line operation, and which operating half hung up, the operation for the current interval, it sorted descending according to the third weight.

Which in some cases is not enough to consider, first appeared in a number of two disjoint intervals, followed by a large weight range covers small weights range, then there is no then the.

Note that the second case to take the intersection, the intersection is the ownership value of the current range of weights.

So the first case, direct lmax, rmin maintain the intersection on it.if (lmax > rmin) return 挂了;

Then, for the second case, there is provided a nominal excellent disjoint-set approach is to maintain the disjoint-set each element extending rightmost point i p. This is based on the last and each x set to update.

Taking into account the descending sort is, when the current intersection is [lmax, rmin] and (may be understood by means of standard process)find(lmax) > rmin

Since the current weights yet to update the disjoint-set, so before the interval only covers the current range, and the range of some larger weights before, so the situation is not legitimate, belong to the situation two.

Time complexity \ (O (T \ log T) \) .

co int N=1000000+10;
int n,T,fa[N];
struct node{int l,r,x;}p[N],e[N];

il bool operator<(co node&a,co node&b){
    return a.x>b.x;
}
int find(int x){
    return x==fa[x]?x:fa[x]=find(fa[x]);
}

bool check(int k){
    for(int i=1;i<=n+1;++i) fa[i]=i;
    copy(e+1,e+k+1,p+1),sort(p+1,p+k+1);
    int lmax=p[1].l,lmin=p[1].l,rmax=p[1].r,rmin=p[1].r;
    for(int i=2;i<=k;++i){
        if(p[i].x<p[i-1].x){
            if(find(lmax)>rmin) return 0; // 交集被覆盖 
            for(int j=find(lmin);j<=rmax;++j) // 并集合并
                fa[find(j)]=find(rmax+1);
            lmin=lmax=p[i].l,rmin=rmax=p[i].r;
        }
        else{
            lmin=min(lmin,p[i].l),lmax=max(lmax,p[i].l);
            rmin=min(rmin,p[i].r),rmax=max(rmax,p[i].r);
            if(find(lmax)>rmin) return 0;
        }
    }
    if(find(lmax)>rmin) return 0;
    return 1;
}
int main(){
    freopen("number.in","r",stdin),freopen("number.out","w",stdout);
    read(n),read(T);
    for(int i=1;i<=T;++i) read(e[i].l),read(e[i].r),read(e[i].x);
    int l=1,r=T;
    while(l<r){
        int mid=(l+r+1)>>1;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    printf("%d\n",l+1);
    return 0;
}

Guess you like

Origin www.cnblogs.com/autoint/p/test20190815.html