Cdoj 1262 Memory

Source: Internet
Author: User

Small x and small H is a good friend, small h is weak and sickly, but also very forgetful, so I usually eat n bottles of medicine to small X and other people to keep.

One day because of fog all PM2.5, small h of chronic respiratory disease again attack, but when small x took out the bottle, but found abnormal situation.

Small x now has n bottles of medicine, each bottle contains an unlimited number of pills, each tablet weight is strictly equal to 1 grams. However, the nit-picking small x found that the n -bottle drug has 2 bottles of pills in the weight of each tablet is unqualified, substandard pills than the normal pill 0.1g lighter.

Small x now has an electronic weigh(Ability to display specific weights< Span id= "mathjax-span-11" class= "Mrow" >) , due to time-critical, Small x decides to choose from each bottle b I (1 ≤ Bi) tablets, weigh their sums and weigh them only once to find out the number of these two vials of substandard medicine.

Now, what is the sequence b( consisting of bi ) of the smallest dictionary order?

Input

One line of an integer n(2≤n≤)

Output

A row of n digits, 22 spaces separated by a space, note that there is no space at the end.

The main focus is to realize that the sum of any two elements in the sequence is equal to the following code or 2 better feeling ... (especially the red font, very practical skills)
#include <stdio.h>#include<algorithm>#include<Set>using namespacestd;intMainvoid){    intN; intb[ -]; intcnt,temp; inti,j; Set<int>s; scanf ("%d",&N); b[1]=1; b[2]=2; S.insert (3); CNT=3;  for(i=3; i<=n;++i) { while(true) {Temp=1;  for(j=1; j<=i-1;++j) {if(S.count (b[j]+CNT)) {                    ++CNT; Temp=0;  Break; }            }            if(temp==1) {B[i]=CNT;  for(j=1; j<=i-1; ++j) S.insert (b[j]+CNT); ++CNT;  Break; }        }    }        if(n==2) printf ("1 1"); Else{printf ("%d", b[1]);  for(i=2; i<=n;++i) printf ("%d", B[i]); }    }

#include <stdio.h>#include<algorithm>#include<Set>using namespacestd;intb[ -];Set<int>s;BOOLCheckintJintCNT);intMainvoid){    intN; intCNT; scanf ("%d",&N); b[1]=1; b[2]=2; S.insert (3); CNT=3; for (int j=3;cnt<=n;++ j) {if(check (j,cnt)) {b[cnt]=J;  for(intk=1; k<=cnt-1; ++k) S.insert (j+B[k]); ++CNT; }    }        if(n==2) printf ("1 1"); Else{printf ("%d", b[1]);  for(intI=2; i<=n;++i) printf ("%d", B[i]); }}BOOLCheck (intJintCNT) {     for(intI=1; i<=cnt-1;++i) {if(S.count (B[I]+J))return false; }    return true;}

Cdoj 1262 Memory

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.