POJ 1270 Following Orders (DFS,拓扑排序,剪枝)
摘要:1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 using namespace std; 6 char contents[30]; 7 char ans[30]; 8 bool constraints[60][60]; 9 bool visited[30]; //记录了contents[i]是否已被访问过 10 int before[100]; 11 int n=0; 12 /************没加任何限制的,输出
阅读全文
posted @
2012-11-26 17:01
MicZ
阅读(304)
推荐(0)
关于函数的参数传递
摘要:首先看如下代码:void creatBtree(Node* head) //按前序生成树。{ head=new Node(); Node* p=head; int t; scanf("%d",&t); if(t==-1)return; else p->data=t; creatBtree(p->left); creatBtree(p->right); printf("%在函数里,head的地址为%d\n",head); return;}int main(){ Head *head; freopen("tree.txt&
阅读全文
posted @
2012-11-23 00:16
MicZ
阅读(304)
推荐(0)
文件操作的小tips
摘要:freopen 功 能: 替换一个流,或者说重新分配文件指针,实现重定向。eg: freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);/* close the standard output stream */ fclose(stdout);若要返回到显示默认的 stdout,使用下面的调用: freopen( "CON", "w", stdout ); //输出到控制台"CON" freo
阅读全文
posted @
2012-11-22 00:04
MicZ
阅读(109)
推荐(0)
乱七八糟
摘要:#line line_number "filename"语法: #line line_number "filename"
#line命令是用于更改__LINE__ 和 __FILE__变量的值. 文件名是可选的. __LINE__ 和 __FILE__ 变量描述被读取的当前文件和行. 命令 #line 10 "main.cpp" 更改行号为10,当前文件改为"main.cpp". 意思是说 这里将使用main.cpp文件中的第十行命令-----------------------------------------
阅读全文
posted @
2012-11-20 19:23
MicZ
阅读(223)
推荐(0)
Ordered Fractions(二叉搜索树)
摘要:题意:输入一个n,按从小到大的顺序输出从0到1之间的所有分母不大于n的最简分数。比较容易想到的是排序。可以用结构体表示一个分数,将所有符合条件的分数都存到数组里,然后sort一下,输出就行。注意cmp函数的写法bool cmp(node x,node y)
{ return x.a*y.b<x.b*y.a; //比较两个分数的大小,交叉相乘
}最近刚学了二叉树,可以用二叉查找树,实现插入排序。0/1和1/1这两个值只能逼近不能达到,直接输出即可。根据二叉查找树的性质,显然1/2是该树的head。然后分子分母从小到大,往树里进行插入。如果发现树中已有相同的值,说明该分数不是最简,而且已经有
阅读全文
posted @
2012-11-18 23:41
MicZ
阅读(242)
推荐(0)