BZOJ2882: Craft

Source: Internet
Author: User

Exercises

Bare string Minimum representation ...

Can poke here: http://www.cnblogs.com/ACAC/archive/2010/05/23/1742349.html

Here's why a[i+k]>a[j+k] can let me jump to i+k+1

That is to say i-i+k this paragraph will not have a suffix to be the smallest representation of the prefix, then we just construct a smaller than it can be.

Obviously if we take a[i+x]--a[i+k+1], we always have a[j+x]--a[j+x+1] smaller than it is, which is not the smallest when the length is less than Len, so it cannot be the smallest representation.

So let's raise the point to see how long it can extend is always the smallest of the same length, which is the smallest representation when the length is Len.

And finally why return to Min (i,j)

Because... Dig Pit to fill ...

Code:

1#include <cstdio>2 3#include <cstdlib>4 5#include <cmath>6 7#include <cstring>8 9#include <algorithm>Ten  One#include <iostream> A  -#include <vector> -  the#include <map> -  -#include <Set> -  +#include <queue> -  +#include <string> A  at #defineINF 1000000000 -  - #defineMAXN 300000+5 -  - #defineMAXM 20000000+5 -  in #defineEPS 1e-10 -  to #definell Long Long +  - #definePA pair<int,int> the  * #defineFor0 (i,n) for (int i=0;i<= (n); i++) $ Panax Notoginseng #defineFor1 (i,n) for (int i=1;i<= (n); i++) -  the #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) +  A #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) the #defineFor4 (i,x) for (int i=head[x],y;i;i=e[i].next) +  - #defineMoD 1000000007 $  $ using namespacestd; -  -InlineintRead () the  - {Wuyi  the     intx=0, f=1;CharCh=GetChar (); -  Wu      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -  About      while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} $  -     returnx*F; -  - } A intN,A[MAXN]; +  the intMain () -  $ { the  theFreopen ("Input.txt","R", stdin); the  theFreopen ("output.txt","W", stdout); -  inn=read (); theFor0 (i,n-1) a[i]=read (); the     intI=0, j=1, k=0; About      while(i<n&&j<n&&k<N) the     { the         intt=a[(i+k)%n]-a[(j+k)%n]; the         if(!t) k++; +         Else -         { thek=0;Bayi             if(t>0) i+=k+1;Elsej+=k+1; the             if(I==J) i++; the         } -     } -     intans=min (i,j); theprintf"%d", a[ans%n]); theFor1 (i,n-1) printf ("%d", a[(ans+i)%n]);  the  the     return 0; -  the}
View Code 2882: Process time limit:10 Sec Memory limit:128 MB
submit:48 solved:24
[Submit] [Status] DescriptionXiaomin and Xiao Yan are a pair of good friends. They are playing a magical game called Minecraft. They are now going to make a strip of crafts made of blocks. But the blocks are now messy, and because of the machine's requirements, they can only do the most left-hand block of the handicraft on the far right. they thought, in this one operation alone, the most beautiful crafts can be more beautiful. Two Crafts Beautiful comparison method is, from the beginning to compare, if the first position of the block is not the same then who the defect degree is small, then who is more beautiful, if the same then continue to compare the i+1 block. If it's all the same, then the two crafts are just as beautiful. InputThe first line is two integer n, which represents the number of squares. The second row n integers, each of which outputs the value of the square defect in order from left to right. Outputa row of n integers representing the value of the most aesthetically pleasing artifacts from left to right. Sample Input
10
10 9 8 7 6 5 4 3 2 1
Sample Output
1 9 8 7 6 5 4 3 2HINT



"Data size and conventions"

For 20% of data, n<=1000

For 40% of data, n<=10000

For 100% of data, n<=300000

BZOJ2882: Craft

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.