ACM/ICPC recursion (poj2663-fully covered +poj1057 (hundred practice 2775)-Legacy file Structure chart)

Source: Internet
Author: User
Tags strcmp

poj2663-fully covered

See the first note

//simple recursion-three 3*2 (a) make a draft for a unit to draw the law//The test instructions -3*n block can be fully covered by the 1*2 of the minocycline in a number of cases//Memory 132K time:0 Ms#include<iostream>#include<cstring>#include<cstdio>using namespacestd;intans;//Start tilingintTiling (intN) {    intsum =0; if(n = =0)        return 1; Else if(N >=2) {sum+=3* Tiling (N-2);  while(N-=2N2>=0) Sum+=2*tiling (n2); }    returnsum;}intMain () {intN;  while(SCANF ("%d", &n), n! =-1) {ans=Tiling (n); printf ("%d\n", ans); }    return 0;}

POJ1057 (Practice 2775)-Legacy file structure diagram

non-recursive version -note the status of the recording

//legacy shell File Structure diagram simulation-parse file (recursive)//memory:148k time:0 Ms#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespacestd;#defineMAX 62CharBuff[max][max];/*File name*/structfile{CharF[max];};/*Folder Property*/structfolder{intCatalog; intnum; File F[max];} Dir[max];/*sort_cmp*/BOOLCMP (File a,file b) {returnstrcmp (A.F, B.F) <0;}voidOpen_folder (intCurintNum//cur-Current file directory, number of num-files{    intI, J; Sort (DIR[CUR].F, dir[cur].f+num, CMP);  for(i =0; i < num; i++)    {         for(j =0; J < Dir[cur].catalog; J + +) printf ("| "); printf ("%s\n", DIR[CUR].F[I].F); }}intMain () {intT, N; intI, j, K; T=0;  while(SCANF ("%s", buff[0]), buff[0][0] !='#')    {        /*Reading All*/N=0; K=0;  while(SCANF ("%s", Buff[++n]), buff[n][0] !='*'); printf ("DATA SET%d:\n",++T); printf ("root\n"); dir[0].num =0;//Init         for(i =0; I <= N; i++)        {            if(buff[i][0] =='D')//Folder{k++; Dir[k].catalog= dir[k-1].catalog+1; Dir[k].num=0;  for(j =0; J < Dir[k].catalog; J + +) printf ("| "); printf ("%s\n", Buff[i]); }            Else if(buff[i][0] =='F')//Filestrcpy (dir[k].f[dir[k].num++].f, buff[i]); Else if(buff[i][0] ==']')//End_folder{Open_folder (k, dir[k].num); K--; }            Else if(buff[i][0] =='*')//End_rootOpen_folder (k, dir[k].num); } printf ("\ n"); }    return 0;}

recursive version -record status with formal parameters

-ps: This version is written on the day of the publication, so there are some differences between the habits and the extremes of the previous version (which was done last year).

//Recursive simulation//memory:184k time:0ms#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;#defineMAX 31intT//The current example of the first TCharCur[max];//Current input string//FILE *out = fopen ("OUT.txt", "w");structFile {CharName[max]; FriendBOOL operator<(file A, file b) {if(strcmp (A.name, B.name) <0)return true; Else return false; }};structCatalog {CharName[max]; intNum//number of files in this directoryFile F[max]; Catalog (Char*name) {strcpy ( This->name, name); num =0; }};voidOpenChar*name,intLevel ) {    if(name[0] =='R')//before root inputprintf"DATA SET%d:\n", ++T); //fprintf (out, "\ndata SET%d:\n", ++t);     while(level--) printf ("| "); //fprintf (out, "| ");printf"%s\n", name); //fprintf (out, "%s\n", name);}voidRoot (Catalog dir,intLevel ) {scanf ("%s", cur); if(cur[0] =='#')return;//ENDOpen (Dir.name, level);  Do{        if(cur[0] =='D') {Catalog newdir (cur); //Create a new folder named CurRoot (Newdir, level +1); }        Else if(cur[0] =='F') strcpy (Dir.f[dir.num++].name, cur); Else{//cur[0] = = '] ' or cur[0] = = ' * 'Sort (DIR.F, DIR.F +dir.num);  for(inti =0; i < Dir.num; i++) Open (Dir.f[i].name, level); return; }    } while(SCANF ("%s", cur));}intMain () { while(cur[0] !='#') {Catalog R ("ROOT");//creating the root directoryRoot (R,0); printf ("\ n"); }    return 0;}

ACM/ICPC recursion (poj2663-fully covered +poj1057 (hundred practice 2775)-Legacy file Structure chart)

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.