
Judge Online
文章平均质量分 62
无边际的梦想无止境的追求
有一种力量,无人能抵挡,它永不言败,生来倔强;有一种理想,照亮了迷茫,在这写满荣耀的地方
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Zhejiang university----Hello World for U
//Zhejiang university----Hello World for U/*时间限制 1s 内存限制 128M题目描述: Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. For example, "hellow原创 2016-03-29 15:42:58 · 271 阅读 · 0 评论 -
Zhejiang university----Sharing
//Zhejiang university----Sharing/*时间限制 1s 内存限制128M题目描述: To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the w原创 2016-03-29 16:04:48 · 355 阅读 · 0 评论 -
Zhejiang university----To Fill or Not to Fill
//Zhejiang university----To Fill or Not to Fill/*时间限制 1s 内存限制 128M题目描述: With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a原创 2016-03-29 16:21:53 · 230 阅读 · 0 评论 -
Zhejaing university----Head of a Gang
//Zhejiang university----Head of a Gang/*时间限制 1s 内存限制 128M题目描述: One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call between A and原创 2016-03-29 16:53:07 · 264 阅读 · 0 评论 -
OJ 常见错误总结
Accepted ====》答案正确Wrong answer ====》代码的正确性问题 或者 代码的健壮性 (边界数据,变量出现溢出)Presentation Error ====》输出格式错误Time Limit Exceeded====》时间复杂度 或者 死循环 或者 边界数据 Run Time Error====》程序访问了不该访问的内存地址,如访问数组原创 2016-03-05 20:16:36 · 670 阅读 · 0 评论 -
栈 之 寻找下一个较大元素 next greater element
//栈 之 寻找下一个较大元素 next greater element#include #include #include using namespace std;void findnge(int arr[],int len){stack s;s.push(arr[0]);int i=1;int top,next;for(i=1;inext = arr原创 2016-02-24 11:53:07 · 384 阅读 · 0 评论 -
用栈实现表达式求值
#include"stdio.h"#include"stdlib.h" #include"string.h" #include"math.h"#define true 1 #define false 0 #define OPSETSIZE 8 typedef int Status; unsigned char Prior[8][8] ={ // 运算符优原创 2016-02-24 11:39:34 · 943 阅读 · 0 评论 -
二叉树 之 寻找某个结点所有的祖先
#include #include #include using namespace std;struct node{int data;struct node* left;struct node* right;};struct node* newnode(int data){struct node* node = (struct node*) malloc(原创 2016-02-24 11:32:25 · 1935 阅读 · 1 评论 -
二叉树 之 非递归前序遍历
#include #include #include #include using namespace std;struct node{int data;struct node* left;struct node* right;};struct node* newnode(int data){struct node* node = new struct原创 2016-02-24 11:22:41 · 218 阅读 · 0 评论 -
二叉树 之 中序遍历 (不使用栈和递归)
#include#includestruct tNode{ int data; struct tNode* left; struct tNode* right;};void MorrisTraversal(struct tNode *root){ struct tNode *current,*pre; if(roo原创 2016-02-24 10:54:06 · 507 阅读 · 0 评论 -
二叉树 之 lowest common ancestor 最低公共祖先
#include //lca lowest common ancestor 时复o(n)#include using namespace std;struct node{//二叉树结点int key;struct node *left, *right;};node * newnode(int k){//公用函数,生成一个节点node *temp = new nod原创 2016-02-24 10:41:03 · 372 阅读 · 0 评论 -
线性表 之 数组调整顺序
//数组顺序调整,奇数位于偶数前,没有要求相对位置不变#include int main(){ int i, j, k, n, t ,arr[100000]; bool first; while (scanf("%d", &n) != EOF) { first = true; k = 0; f原创 2016-02-24 10:24:05 · 282 阅读 · 0 评论 -
线性表 之 链表反转
//时间复杂度 O(N)#include #include struct node{int data;struct node* next;};static void reverse(struct node** head_ref){struct node* prev = NULL;struct node* current = *head_ref;struct原创 2016-02-23 23:29:29 · 440 阅读 · 0 评论 -
大数运算模板
#include #include #include #include using namespace std; #define MAXN 9999#define MAXSIZE 10#define DLEN 4class BigNum{ private: int a[500]; //可以控制大数的位数 int len;原创 2016-02-23 22:30:25 · 217 阅读 · 0 评论 -
中缀表达式转换后缀表达式
#include#includetypedef struct{char s[20][20];int top;}SQ;void copystr(char *a,char *b){ int i=0; do { b[i]=a[i]; i++; } while(a[i]!='\0'); b[i]原创 2016-02-18 15:43:26 · 264 阅读 · 0 评论 -
reading note 2
//longest consecutive sequence//given an unsorted array of integers, find the length of the longest //consecutive elements sequence. //先排序,然后求解时间复杂度o(nlogn)//your algorithm should be run in o(原创 2016-02-09 17:40:32 · 312 阅读 · 0 评论 -
reading note 1
//判断两个浮点数a和b是否相等a == b ====> fabs(a-b) //判断一个整数是否为奇数(x可能是负数)x % 2 ==1 =====>x % 2 != 0//char的值作为数组下标(char可能是负数)先强制转型为unsigned char,再用作下标//vector和string性能优先于动态分配的数组vector > ary(row_num,ve原创 2016-02-08 17:41:01 · 276 阅读 · 0 评论 -
字符串去特定字符
2原创 2016-02-08 14:10:42 · 280 阅读 · 0 评论 -
tips
/*//滚动数组===>常数优化,减少代码量for(int i =1;i for(int j = 1;j dp[i][j] = max(dp[i-1][j-1],dp[i-1][j-1];}} int ans = dp[n][m];因为每次状态转移仅与上一行有关,二维数组优化为一维数组for(int i = 1;i for(int原创 2016-02-08 14:26:52 · 315 阅读 · 0 评论 -
单词替换
1原创 2016-02-08 14:10:34 · 339 阅读 · 0 评论 -
STL之map
/*gets(str) 读入输入中一整行的数据保存在str中,直到换行符为止,并且删除该换行符2 3(换行)test(换行)gets语句,读到字符为换行符为止,并且去除该换行符scanf("%s",str)函数,读到出现空格或者换行符为止,并不删除紧跟的空格和换行符scanf("%d%d",&a,&b);正确的处理方式为:scanf("%d%d",&a,&b);原创 2016-02-08 13:57:17 · 236 阅读 · 0 评论 -
STL之string
/*标准模板库(STL)队列queue,堆,堆栈,vector,string,map #include //注意区别于string.h using namespace std;//使用标准命名空间 string s; //定义string对象s cin >> s;//输入string对象 或者 char str[] = "test"; s原创 2016-02-08 12:57:28 · 224 阅读 · 0 评论 -
dp 多重背包
/*题目1455:珍惜现在,感恩生活题目描述:为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。请问:你用有限的资金最多能采购多少公斤粮食呢?输入:输入数据首先包含一个正整数C,表示有C组测试用例,每组测试用例的第一行是两个整数n和m(1输出:对于每组测试原创 2016-02-08 12:22:31 · 299 阅读 · 0 评论 -
dp 完全背包
/*题目1454:Piggy-Bank题目描述:Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (I原创 2016-02-08 12:18:28 · 268 阅读 · 0 评论 -
dp 0-1
/*dp递推dp LISdp LCSdp 状态和状态转移dp 0-1背包 完全背包 多重背包对问题的抽象===>题目1123:采药题目描述:辰辰是个很有潜能、天资聪颖的孩子,他的梦想是称为世界上最伟大的医师。为此,他想拜附近最有威望的医师为师。医师为了判断他的资质,给他出了一个难题。医师把他带到个到处都是草药的山洞里对他说:“孩子,这个山洞里有一些不原创 2016-02-08 10:24:19 · 286 阅读 · 0 评论 -
dp之状态和状态转移 2
/*题目1453:Greedy Tino题目描述: Tino wrote a long long story. BUT! in Chinese...So I have to tell you the problem directly and discard his long long story. That is tino want to carry some oranges wi原创 2016-02-07 21:37:01 · 281 阅读 · 0 评论 -
DP之状态和状态转移
/*DP之状态和状态转移题目1452:搬寝室题目描述:搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆,因为n是一个小于2000的整数,实在是太多了,于是xhd决定随便搬2*k件过去就行了.但还是会很累,因为2*k也不小是一个不大于n的整数.幸运的是xhd根据多年的搬东西的原创 2016-02-07 20:34:26 · 704 阅读 · 0 评论 -
DP之最长公共子序列 LCS
/*DP之最长公共子序列 LCSdp[0][j] (0dp[i][0] (0dp[i][j] = dp[i-1][j-1]+1;(s1[i] == s2[j])dp[i][j] = max{dp[i-1][j],dp[i][j-1]} (s1[i] != s2[j])题目1042:Coincidence题目描述:Find a longest common subse原创 2016-02-07 16:41:55 · 250 阅读 · 0 评论 -
合唱队形
//正反两次使用LIS原创 2016-02-07 15:16:12 · 649 阅读 · 0 评论 -
DP之最长递增子序列LIS
/*DP之递推DP之最长递增子序列 LISF[1] = 1;F[i] = max{1,F[j]+1 | aj DP之最长不增子序列F[1] = 1;F[i] = max{1,F[j]+1 | j=ai}*///时间复杂度o(n^2) 空间复杂度o(n)#include int max(int a,int b){return a>b ? a : b;}原创 2016-02-07 15:15:23 · 364 阅读 · 0 评论 -
吃糖果
1原创 2016-02-07 14:21:19 · 282 阅读 · 0 评论 -
动态规划 DP 2
/*错排公式 F[n]=(n-1)*F[n-1] + (n-1)*F[n-2]题目1451:不容易系列之一题目描述:大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样。话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的。比如,我高中的时候,就有一个原创 2016-02-07 14:20:59 · 199 阅读 · 0 评论 -
动态规划 DP 1
/*动态规划DP和搜索斐波那契数列,第一个数是1,第二个数也是1,其后的每一个数都是前两个数的和1,1,2,3,5,8,13......题目1205:N阶楼梯上楼问题题目描述:N阶楼梯上楼问题:一次可以走两阶或一阶,问有多少种上楼方式。(要求采用非递归)输入:输入包括一个整数N,(1输出:可能有多组测试数据,对于每组数据,输出当楼梯阶数是N时的上楼方式个原创 2016-02-07 14:08:33 · 225 阅读 · 0 评论 -
递归(图的遍历)2
/*深度优先搜索 DFSBFS===>层序递增遍历===>最优解DFS===>有没有解题目1461:Tempter of the bone题目描述:The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze be原创 2016-02-07 13:02:22 · 246 阅读 · 0 评论 -
递归(图的遍历)3
1原创 2016-02-07 11:37:27 · 208 阅读 · 0 评论 -
递归(图的遍历)1
/*递归====>图的遍历题目1460:Oil Deposit题目描述:The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land a原创 2016-02-07 09:32:51 · 276 阅读 · 0 评论 -
递归 (枚举)2
/*素数环====>回溯枚举====>递归题目1459:Prime ring problem题目描述:A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in tw原创 2016-02-07 00:00:41 · 252 阅读 · 0 评论 -
递归 (枚举) 1
/*最少,最短,最优====>考虑广度优先搜索题目1458:汉诺塔III(变形汉诺塔)题目描述:约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下、由小到大顺序串着由64个圆盘构成的塔。目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动一个盘,且不允许大盘放在小盘的上面。现在我们改变游戏的玩法,不允许直接从最左(右)边移到最右(左)边原创 2016-02-06 23:18:35 · 305 阅读 · 0 评论 -
搜索(广度优先搜索)BFS 2
/*题目1457:非常可乐题目描述:大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为。因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子,它们的容量分别是N 毫升和M 毫升 可乐的体积为S (S输入:三个整数 : S 可乐的体积 , N 和 M是两个杯子的原创 2016-02-06 22:34:08 · 263 阅读 · 0 评论 -
搜索(广度优先搜索) BFS 1
/*广度优先搜索 BFS(状态查找树+剪枝)题目1456:胜利大逃亡题目描述:Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会.魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,现在知道魔王将在T分钟后回到城堡,Igna原创 2016-02-06 21:38:17 · 305 阅读 · 0 评论