POJ2663-完全覆盖

题解见首注释

//简单递推-三个米诺牌(3*2)为一个单位打草稿得出规律
//题意-3*n块方格能被1*2的米诺牌以多少种情况完全覆盖
//Memory 132K Time: 0 Ms #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; int ans; //开始平铺
int Tiling(int n)
{
int sum = ;
if (n == )
return ;
else if (n >= )
{
sum += * Tiling(n - );
while (n -= , n - >= )
sum += *Tiling(n-);
}
return sum;
} int main()
{
int n;
while (scanf("%d",&n),n != -)
{
ans = Tiling(n);
printf("%d\n", ans);
}
return ;
}

POJ1057(百练2775)-旧式文件结构图

非递归版-注意记录状态

//旧式shell文件结构图模拟-分析文件(可递归)
//Memory: 148K Time: 0 Ms #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std; #define MAX 62 char buff[MAX][MAX]; /* File name */
struct File{
char f[MAX];
}; /* Folder property */
struct Folder{
int catalog;
int num;
File f[MAX];
}dir[MAX]; /* sort_cmp */
bool cmp(File a,File b)
{
return strcmp(a.f, b.f) < ;
} void open_Folder(int cur,int num) //cur-当前文件目录,num-文件数
{
int i, j;
sort(dir[cur].f, dir[cur].f + num, cmp);
for (i = ; i < num; i++)
{
for (j = ; j < dir[cur].catalog; j++)
printf("| ");
printf("%s\n", dir[cur].f[i].f);
}
} int main()
{
int T, n;
int i, j, k;
T = ;
while (scanf("%s", buff[]), buff[][] != '#')
{
/*Reading all*/
n = ;
k = ;
while (scanf("%s", buff[++n]), buff[n][] != '*');
printf("DATA SET %d:\n",++T);
printf("ROOT\n");
dir[].num = ; //Init for (i = ; i <= n; i++)
{
if (buff[i][] == 'd') //Folder
{
k++;
dir[k].catalog = dir[k-].catalog+;
dir[k].num = ;
for (j = ; j < dir[k].catalog; j++)
printf("| ");
printf("%s\n", buff[i]);
}
else if (buff[i][] == 'f') //File
strcpy(dir[k].f[dir[k].num++].f, buff[i]);
else if (buff[i][] == ']') //end_Folder
{
open_Folder(k, dir[k].num);
k--;
}
else if (buff[i][] == '*') //end_root
open_Folder(k, dir[k].num);
}
printf("\n");
}
return ;
}

递归版-用形参记录状态

-PS:这个版本是本文发表当天写的,所以和上面版本(前一年做过的)的习惯和极值有些差异。

//递归模拟
//Memory:184K Time:0Ms
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; #define MAX 31 int T; //当前为第T个样例
char cur[MAX]; //当前输入字符串 //FILE *out = fopen("out.txt", "w"); struct File {
char name[MAX];
friend bool operator < (File a, File b)
{
if (strcmp(a.name, b.name) < ) return true;
else return false;
}
}; struct Catalog {
char name[MAX];
int num; //该目录下的文件数
File f[MAX];
Catalog(char *name) { strcpy(this->name, name); num = ; }
}; void open(char *name,int level)
{
if (name[] == 'R') //ROOT前输入
printf("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);
} void root(Catalog dir,int level)
{
scanf("%s", cur); if (cur[] == '#') return; //END open(dir.name, level); do{
if (cur[] == 'd')
{
Catalog newDir(cur); //创建新文件夹,命名为cur
root(newDir, level + );
}
else if(cur[] == 'f')
strcpy(dir.f[dir.num++].name, cur);
else { //cur[0] == ']' or cur[0] == '*'
sort(dir.f, dir.f + dir.num);
for (int i = ; i < dir.num; i++)
open(dir.f[i].name, level);
return;
}
}while (scanf("%s", cur));
} int main()
{
while (cur[] != '#')
{
Catalog r("ROOT"); //创建根目录
root(r,);
printf("\n");
} return ;
}

ACM/ICPC 之 递归(POJ2663-完全覆盖+POJ1057(百练2775)-旧式文件结构图)的更多相关文章

  1. 【转】lonekight@xmu·ACM/ICPC 回忆录

    转自:http://hi.baidu.com/ordeder/item/2a342a7fe7cb9e336dc37c89 2009年09月06日 星期日 21:55 初识ACM最早听说ACM/ICPC ...

  2. 2017 ACM ICPC Asia Regional - Daejeon

    2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...

  3. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  4. ACM ICPC 2017 Warmup Contest 9 I

    I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...

  5. 训练报告 (2014-2015) 2014, Samara SAU ACM ICPC Quarterfinal Qualification Contest

    Solved A Gym 100488A Yet Another Goat in the Garden   B Gym 100488B Impossible to Guess Solved C Gym ...

  6. 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛

    比赛链接: http://202.197.224.59/OnlineJudge2/index.php/Contest/problems/contest_id/36 题目来源: 2014嘉杰信息杯ACM ...

  7. ACM/ICPC 之 BFS(离线)+康拓展开(TSH OJ-玩具(Toy))

    祝大家新年快乐,相信在新的一年里一定有我们自己的梦! 这是一个简化的魔板问题,只需输出步骤即可. 玩具(Toy) 描述 ZC神最擅长逻辑推理,一日,他给大家讲述起自己儿时的数字玩具. 该玩具酷似魔方, ...

  8. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering

    Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...

  9. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time

    Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...

随机推荐

  1. swift错误和异常处理

    异常 (exception) 和错误 (error). 在 Objective-C 开发中,异常往往是由程序员的错误导致的 app 无法继续运行,比如我们向一个无法响应某个消息的NSObject 对象 ...

  2. step 3 socket

    socket 网络通讯三要素 IP地址(主机名) 网络中设备的标示 不易记忆,可以用主机名 本地回环地址:127.0.0.1 主机名:localhost 每台计算机都有一个 127.0.0.1 如果 ...

  3. [工具]Swagger-api接口文档描述

    摘要 工作中经常的用到webapi,之前都是提供的使用postman模拟请求的截图,非常的不方便,如果能在项目中集成一个在线查看接口说明的地方,肯定更方便更直观.在网上看到swagger这个组件,界面 ...

  4. CentOS 与 RedHat 关系和区别

    转自http://www.aixchina.net/club/archiver/tid-26784.html CentOS 发行版介绍 CentOS 是 Community ENTerprise Op ...

  5. Linux服务器管理: 系统的进程管理后台进程的切换和相关命令

    1.把进程放入到后台: [root@localhost/]#tar -zcf etc.tar.gz /etc &           //这种方法是在后台运行的 [root@localhost ...

  6. Redis在WEB开发中的应用与实践

    Redis在WEB开发中的应用与实践 一.Redis概述: Redis是一个功能强大.性能高效的开源数据结构服务器,Redis最典型的应用是NoSQL.但事实上Redis除了作为NoSQL数据库使用之 ...

  7. CF451C Predict Outcome of the Game 水题

    Codeforces Round #258 (Div. 2) Predict Outcome of the Game C. Predict Outcome of the Game time limit ...

  8. PHP无限极分类生成树方法,无限分级

    你还在用浪费时间又浪费内存的递归遍历无限极分类吗,看了该篇文章,我觉得你应该换换了.这是我在OSChina上看到的一段非常精简的PHP无限极分类生成树方法,巧在引用,整理分享了. function g ...

  9. WCF服务显示的是服务器名称而不是IP地址...

    打开http://xx.xx.xx.xx:端口号/Service1.svc页面显示的服务地址为: http://xx_yy_server:端口号/Service1.svc?wsdl 是显示的服务器的名 ...

  10. iOS创建子工程

    实际开发中,我们可能会同时开发好几个端,比如楼主目前开发的家教平台,需要老师端,家长端,助教端三个端.有很多工具方法,或者封装的自定义控件都是可以复用的.我们就可以把公用的代码抽取出去,新建一个工程, ...