上一页 1 ··· 4 5 6 7 8 9 10 下一页
摘要: http://acm.pku.edu.cn/JudgeOnline/problem?id=1664还是没理解为什么这么做#include<stdio.h>int dg(int m, int n){ if(m < 0) return 0; if(m == 0 || n == 1) return 1; return dg(m-n, n) + dg(m, n-1);}int main(){ int t, m, n; while(scanf("%d", &t) != EOF) { while(t--) { scanf("%d%d", & 阅读全文
posted @ 2010-05-03 22:57 SubmarineX 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 第一次完成DFShttp://acm.pku.edu.cn/JudgeOnline/problem?id=1164题目求:房间的个数和房间的最大面积。思路:为了调试看起来方便,用8表示墙,用0表示通路(当然房间区域也是可以走通的,所以也用0表示),用(2*row+1)*(2*column+1)的矩阵来表示(0 ≤ i≤ 2*row,0 ≤j≤ 2*column),当 i,j 都为奇数时,点(i , j)表示房间区域, 其余则为墙或门。心得:原先没有想到还有这种情况:3 33 2 61 0 49 8 12经过调试发现,房间区域为8了,但路上还是0,这样就会引起重复计算,对dfs()做了修改:wh 阅读全文
posted @ 2010-05-02 14:30 SubmarineX 阅读(307) 评论(0) 推荐(0) 编辑
摘要: 代码 阅读全文
posted @ 2010-05-02 12:01 SubmarineX 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 排列下一个字典序:从原排列后部开始,对相邻一对进行比较,若前者小于后者,标记前者下标为 j;令 k = len - 1, k 递减,寻找到 order[K ] order[j ] (k j),交换两项;对 order[ j + 1 ] 到 order[k ], 进行从小到大的排序就可以了。代码当然C++里对下一个字典排序是有STL的:不过对于STL,我的观点是:用之前必须弄明白它的原理。代码http://acm.pku.edu.cn/JudgeOnline/problem?id=1256the right order of letters is 'A''a''B''b'...' 阅读全文
posted @ 2010-04-29 21:36 SubmarineX 阅读(248) 评论(0) 推荐(0) 编辑
摘要: http://acm.pku.edu.cn/JudgeOnline/problem?id=1088状态转移方程:DP(i ,j) = max(DP(i - 1, j), DP(i + 1,j), DP(i , j - 1), DP(i , j + 1)) + 1;代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->//刚开始接触DP题,用起来也很不熟练,看了discuss写的#include<stdio.h>int row, co 阅读全文
posted @ 2010-04-27 21:35 SubmarineX 阅读(233) 评论(0) 推荐(0) 编辑
摘要: sort,用到了结构体第一种sort:282MS代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#include<stdio.h>#include<algorithm>using namespace std;struct Array{ char data[30];}dna[20005];bool operator < (Array const& arr1, Array const& arr2) 阅读全文
posted @ 2010-04-22 22:21 SubmarineX 阅读(1997) 评论(0) 推荐(2) 编辑
摘要: 摘自刘汝佳的《算法竞赛入门经典》PreOrder(T) = T 的根结点 + PreOrder(T 的左子树) + PreOrder(T 的右子树);InOrder(T) = InOrder(T 的左子树) + T 的根结点 + InOrder(T 的右子树);PostOrder(T) = PostOrder(T 的左子树) + PostOrder(T 的右子树) + T 的根结点;输入一颗二叉树的先序遍历和中序遍历,输出它的后序遍历。Sample InputSample Output代码也可以省略build()函数的最后一个参数;代码 阅读全文
posted @ 2010-04-22 18:44 SubmarineX 阅读(244) 评论(0) 推荐(1) 编辑
摘要: http://acm.pku.edu.cn/JudgeOnline/problem?id=2376在T天里干完一件事,有多只牛,每只牛负责连续几天,日期可能重叠。找出最少数量的牛干完这件事。(可能讲的不清楚)#include<stdio.h> #include<algorithm> using namespace std; struct ORDER { int left; int right; }order[25001]; bool cmp(ORDER a, ORDER b) { return a.left < b.left; } int main() { int 阅读全文
posted @ 2010-04-21 23:28 SubmarineX 阅读(526) 评论(0) 推荐(0) 编辑
摘要: 转自:http://www.360doc.com/showweb/0/0/24257293.aspx前几天Neo写过《编程中的命名设计那点事》,这里也有另外一篇和程序命名的文章,可以从另一个角度看看。1.- 变量应该是尽可能的望文知意。千万不要使用教材中的命名方式。好的变量:daysDateRange, flightNumber, carColor. 坏的变量:days, dRange, temp, data, aux… 在我们的日常工作中,有很大数量的开发人员喜欢使用短的变量名,而不是有含义的变量名。这主要是因为我们大学教科书的那些示例所造成的,人都是先入为主,所以,教科书中的那些很抽象,带 阅读全文
posted @ 2010-04-21 22:29 SubmarineX 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 转自:http://coolshell.cn/?p=990在我开始设计系统的时候,我会花去很多时间去设计命名,因为好的命名和好的设计是分不开的。In the beginning was the Word, and the Word was with God, and the Word was God太初有道。道与神同在,道就是神。 (约翰福音第一章,第一节)在设计过程中给类,方法和函数好的命名会带来好的设计,虽然这不是一定成立,但是如果坏的命名那一定不会给你带来好的设计。在设计过程,如果你发现你很难命名某一个模块,某个方法时,可能你真正遇到的问题不是难命名的问题,而是这个设计是否真的合理,你或 阅读全文
posted @ 2010-04-21 22:20 SubmarineX 阅读(289) 评论(0) 推荐(0) 编辑
摘要: 最大的和 Time limit: 1000MS Memory limit: 32768K Total Submit: 77 Accepted: 39 Problem Description给出一串 a[1],a[2],a[3]......a[n], 计算出最大的字串和For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.Input第一行给出一个数字 T(1<=T<=20) 代表接下来的组数.接下来每 T 行,开始给出一个数组 N(1<=N<=1000 阅读全文
posted @ 2010-04-21 16:42 SubmarineX 阅读(242) 评论(0) 推荐(0) 编辑
摘要: 目的是 tot = (tot - num + debt[i])一不小心就写成这样了:tot -= num + debt[i];应该是这样的:tot = tot - num + debt[i];代码可是看了很久,才找到错误的,细节决定成败啊;纪念下!!! 阅读全文
posted @ 2010-04-20 21:34 SubmarineX 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 运动会 Time limit: 1000MS Memory limit: 32768K Total Submit: 53 Accepted: 27 学校一年一度的运动会开始了,由于参加的运动员人数相当多使得名单变得杂乱无章,现在给你一张名单让你对这张名单进行排序,使得排序后变得清晰一点。input输入一个整数N(N<10000)代表名单上的人数接下来N行,每行3个整数K,V,P分别代表他们的运气值、实力值和序号(保证没有相同的序号)。output经过排序后输出N行(排序时实力值大的优先,实力值相同则运气值大的优先,如果实力值和运气值都相同则序号小的优先)。每行输出一个序号。sample 阅读全文
posted @ 2010-04-20 17:46 SubmarineX 阅读(374) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.pku.edu.cn/JudgeOnline/problem?id=3618注意没有距离原点等长的两点。abs()用的极妙;先前我的代码写了146行,自己都受不了了,而且提交还是错的,郁闷;后来看了http://ren.javaeye.com/blog/344094 的代码:眼前一亮,没有我之前那么多繁杂的判断。#include<stdio.h>#include<math.h>#include<algorithm>using namespace std;bool cmp(int a, int b){ return abs(a) & 阅读全文
posted @ 2010-04-18 20:05 SubmarineX 阅读(398) 评论(0) 推荐(0) 编辑
摘要: 第一次用结构体,写些自己的心得:#include<stdio.h>#include<algorithm>using namespace std;#define MAX 50000struct COW //定义结构体,(由于在cmp()函数里需要用到结构体名,所以定义了COW,并且结构体变量定义成全局变量){ long long vote1; long long vote2; int num;}cow[MAX+1]; //结构体数组int cmp1(COW a,COW b) //cmp1()在第一次sort()时用到{ return a.vote1 > b.vote 阅读全文
posted @ 2010-04-15 14:38 SubmarineX 阅读(214) 评论(0) 推荐(0) 编辑
摘要: http://acm.pku.edu.cn/JudgeOnline/problem?id=2365鄙视一下自己,净犯低级错误#include<stdio.h>#include<math.h>#define PI 3.141592653589double distance(double x1,double y1,double x2,double y2){ return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));}int main(){ int nNail,i; double x[110],y[110],line 阅读全文
posted @ 2010-04-14 23:19 SubmarineX 阅读(583) 评论(0) 推荐(0) 编辑
摘要: 代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#include<iostream>#include<algorithm>using namespace std;int a[3000001];/*bool cmp(int a, int b){ return a>b; //a>b为从大到小,sort默认从小到大}*/int main (){ int nCase,i; while(scanf("% 阅读全文
posted @ 2010-04-12 21:34 SubmarineX 阅读(255) 评论(0) 推荐(0) 编辑
摘要: 集合划分问题I Time limit: 1000MS Memory limit: 32768K Total Submit: 174 Accepted: 64 问题描述:n个元素的集合{1,2,, n }可以划分为若干个非空子集。例如,当n=4 时,集合{1,2,3,4}可以划分为15 个不同的非空子集如下:{{1},{2},{3},{4}},{{1,2},{3},{4}},{{1,3},{2},{4}},{{1,4},{2},{3}},{{2,3},{1},{4}},{{2,4},{1},{3}},{{3,4},{1},{2}},{{1,2},{3,4}},{{1,3},{2,4}},{{1 阅读全文
posted @ 2010-04-12 20:24 SubmarineX 阅读(710) 评论(0) 推荐(0) 编辑
摘要: 排列的字典序问题 Time limit: 1000MS Memory limit: 32768K Total Submit: 104 Accepted: 38 问题描述:n个元素{1,2,, n }有n!个不同的排列。将这n!个排列按字典序排列,并编号为0,1,…,n!-1。每个排列的编号为其字典序值。例如,当n=3时,6 个不同排列的字典序值如下:字典序值 01 2 3 4 5排列 123 132 213 231 312 321算法设计:给定n以及n个元素{1,2,, n }的一个排列,计算出这个排列的字典序值,以及按字典序排列的下一个排列。数据输入:输出元素个数n。接下来的1 行是n个 阅读全文
posted @ 2010-04-12 19:56 SubmarineX 阅读(6399) 评论(0) 推荐(1) 编辑
摘要: 众数问题 Time limit: 5000MS Memory limit: 32768K Total Submit: 1128 Accepted: 276 问题描述:给定含有n个元素的多重集合S,每个元素在S中出现的次数称为该元素的重数。多重集S中重数最大的元素称为众数。例如,S={1,2,2,2,3,5}。多重集S的众数是2,其重数为3。对于给定的由n 个自然数组成的多重集S,计算S的众数及其重数。数据输入:输入多重集S中元素个数n;接下来的n行中,每行有一个自然数。结果输出:输出第1行给出众数,第2 行是重数。Sample Input6122235Sample Output23注意本题数据 阅读全文
posted @ 2010-04-12 14:25 SubmarineX 阅读(792) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 下一页