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. 缺陷跟踪系统Mantis Bug Tracker

    缺陷管理平台Mantis,也做MantisBT,全称Mantis Bug Tracker. 项目在github的地址:https://github.com/mantisbt/mantisbt Mant ...

  2. c语言中time相关函数

    工作中遇到的函数: int seed = time(NULL); srand(seed); signal(SIGINT, stop); signal(SIGUSR1, sig_usr1); 搜time ...

  3. C#数字格式化

    格式规范的完整形式:{index [,width][:formatstring]} index是此格式程序引用的格式字符串之后的参数,从零开始计数:width(可选) 是要设置格式的字段的宽度,wid ...

  4. fastJSON☞JSONParameters☞时区的修改☞时间最后有一个"Z"

    why... 为什么会有这个问题; 由于近期用到需要将数据序列化... 最终选择了fastJSON(版本为1.)来实现. 但是发现了一个问题,表中有一个dateTime类型的字段, 本来数据库中存入的 ...

  5. ASP CDONTS.NEWMAIL组件发送电邮(附下载)

    附CDONT.NEWMAIL组件下载地址:http://files.cnblogs.com/files/colinliu/cdonts.rar ASP常规发送方法: <% dim mail se ...

  6. PHP 文件与文件夹的创建和删除操作

    创建文件夹: mkdir("D:/test");可以创建多级目录,如果存在,则会报错 if(!is_dir($path)) {     if(mkdir($path)){      ...

  7. I’ve seen the world,lit it up as my stage now

    I've seen the world,lit it up as my stage now 阅尽繁华 点亮红尘做舞台 Channeling angels in,the new age now 粉末登场 ...

  8. js字符串与16进制互相转换

    // \x65\x76\x61\x6c是否启用\x加密 <script type="text/javascript"> function JavaDe() { var ...

  9. telnet: connect to address 127.0.0.1: Connection refused

    telnet协议是TCP/IP协议族中的一员,是Internet远程登陆服务的标准协议和主要方式.它为用户提供了在本地计算机上完成远程主机工作的能力.在终端使用者的电脑上使用telnet程序,用它连接 ...

  10. BZOJ3223——Tyvj 1729 文艺平衡树

    1.题目大意:维护序列,只有区间翻转这个操作 2.分析:splay的经典操作就是实现区间翻转,就是在splay中有一个标记,表示这个区间被翻转了 然后就是记得各种的操作访问某个点时,记得下传,顺便交换 ...