2012年11月26日
摘要: 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 阅读(288) 评论(0) 推荐(0) 编辑
  2012年11月23日
摘要: 首先看如下代码: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 阅读(294) 评论(0) 推荐(0) 编辑
  2012年11月22日
摘要: 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 阅读(106) 评论(0) 推荐(0) 编辑
  2012年11月20日
摘要: #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 阅读(214) 评论(0) 推荐(0) 编辑
  2012年11月18日
摘要: 题意:输入一个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 阅读(225) 评论(0) 推荐(0) 编辑
  2012年10月30日
摘要: ofstream是从内存到硬盘,ifstream是从硬盘到内存,其实所谓的流缓冲就是内存空间;在C++中,有一个stream这个类,所有的I/O都以这个“流”类为基础的,包括我们要认识的文件I/O,stream这个类有两个重要的运算符:1、插入器(<<) 向流输出数据。比如说系统有一个默认的标准输出流(cout),一般情况下就是指的显示器,所以,cout<<"Write Stdout"<<'\n';就表示把字符串"Write Stdout"和换行字符('\n')输出到标准输出流。2、析取 阅读全文
posted @ 2012-10-30 10:51 MicZ 阅读(293) 评论(0) 推荐(0) 编辑
  2012年10月24日
摘要: #include <cstdio> #include <cstring> using namespace std; const int num_char=26; struct TrieNode { TrieNode *branch[num_char]; TrieNode *fail; int count;//if this is the last node of the word TrieNode() { fail=NULL; count=0; memset(branch,NULL,sizeof(bra... 阅读全文
posted @ 2012-10-24 18:44 MicZ 阅读(191) 评论(0) 推荐(0) 编辑
  2012年10月21日
摘要: 题意:先给出商品个数n,然后对于每一个商品ai{pa,da},pa代表这个商品的利润,da代表这个商品必须在第d天之前售出. 每天只能卖出一个商品问如何安排卖的顺序,使得利润最大.输出最大利润分析:根据贪心的策略,按利润排序,利润最大的放在最前面.按ddl分集合ddl=1的集合,只能在0~1的时间卖.ddl!=1的集合,除了在ddl那天卖,还能在ddl之前的某一天卖,所以将ddl的商品,做成ddl-1的商品的子树.#include <iostream> //按deadline进行分集合 #include <cstdio> #include <memory.h> 阅读全文
posted @ 2012-10-21 15:53 MicZ 阅读(332) 评论(0) 推荐(0) 编辑
  2012年10月19日
摘要: 题意:给k个任务,每一个任务都能被Computer A的x_mode或Computer B的y_mode处理。mode的转换需要重启。问如何安排任务的处理顺序,可以使得重启的次数最少。分析:二分图匹配。将每一个任务看成一条边,端点分别是Computer A的x_mode和Computer B的y_mode。求最小覆盖,即用最少的点数,使得每一条边至少都有一个点与它相连。根据最小覆盖=最大匹配。求该二分图的最大匹配即可。使用匈牙利算法。代码如下:#include <iostream> #include <cstdio> #include <memory.h> 阅读全文
posted @ 2012-10-19 08:49 MicZ 阅读(154) 评论(0) 推荐(0) 编辑
  2012年10月6日
摘要: 感觉对线段树快有阴影了。。还是先从最简单的开始吧。关键是理解原理。求区间最小值:题目:2 //testcases5 3 //n:数组元素个数,m:查询次数78 1 22 12 3 //输入数组,每个数最大值不超过10^51 2 //查询从l到r上的最小值3 54 4#include <cstdio> #include <algorithm> #define lson l , m , rt << 1 #define rson m + 1 , r , rt << 1 | 1 using namespace std; const int maxn = 阅读全文
posted @ 2012-10-06 09:43 MicZ 阅读(209) 评论(0) 推荐(0) 编辑