9 degree question 1377: slow change sequence, 9 degrees 1377

Source: Internet
Author: User

9 degree question 1377: slow change sequence, 9 degrees 1377

Reprinted please indicate this article link http://blog.csdn.net/yangnanhai93/article/details/40474355

Question link address: http://ac.jobdu.com/problem.php? Pid = 1, 1377

The difficulty of this question lies in how to analyze the characteristics of the slow variable sequence:

1: The sequence must be consecutive after the slow-changing sequence is sorted.

Proof: assume that the sorted sequence is a [1] a [2] a [3]... a [n], where a [n]-a [n-1]> 1, that is, an is not consecutive with the preceding number, because the Slow Variable Sequence requires that the changes before and after any number are 1, but for a [n], no number can satisfy the nature of the Slow Variable Sequence before and after it, therefore, the sorted array must be continuous.

2: The Slow Variable Sequence must meet the requirement of forming A new array as array A, which has the following properties:

A [1] = a1, A [n] = an-A [n-1]. when A [n] of 1-n must meet A [n] = 0 and 1-(n-1: A [n]> 0 (array A indicates the number of remaining positions to be filled)

Proof: When 1-(n-1) is counted as m, if A [m] <= 0, then we can obtain A [m] = 0, just get A slow-changing sequence. If A [m] <0, it means that the number of m is less than the number of m-bit, it certainly cannot meet the requirements.

For n bits, as described above, A [n] = 0 makes the number to be filled by the slow variable sequence exactly meet.

The following figure is used to help you understand the problem. By drawing a line, you obviously know that the vertices of the previous layer must be greater than the vertices of the next layer (except for the last layer ), must also meet A [n] = 0

#include <iostream>#include <memory.h>using namespace std;int main(){    //freopen("data.in","r",stdin);    int num,A[10001],tmp,low,high;    while(cin>>num)    {        memset(A,0,sizeof(A));        for(int i=0;i<num;i++)        {            cin>>tmp;            A[tmp]++;        }        low=0;        while(A[low]==0)            low++;        tmp=0;        high=low;        while(A[high]!=0)        {            tmp+=A[high];            high++;        }        if(num==tmp)        {            bool isTrue=true;            tmp=0;            for(int i=low;i

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.