
算法
文章平均质量分 66
sffsdfdfgfdgfd
这个作者很懒,什么都没留下…
展开
-
初次dp
http://acm.pku.edu.cn/JudgeOnline/problem?id=1163 这是我第一次用动态规划来做题。很不熟练啊。从下往上依次考察(i,j)下面的较大数,并储存起来。#include#includeint n,input[100][100];long storage[100][100];int d(int i,int j){ if原创 2010-02-27 10:51:00 · 291 阅读 · 0 评论 -
位操作应用——异或
<br />http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=4095<br /> Sample Input2aabcdefbzyxwvubzyxwvu4aqwertyeas fghaqwertyeasdfgheasdfghaqwertyaqwerty20x0abcd0ABCDEF0x0abcdSample Outputaabcdefeas fgh0ABC原创 2010-11-14 13:47:00 · 710 阅读 · 0 评论 -
过桥问题
<br />背景:在一个伸手不见五指的黑夜里,有一群人过一独木桥,只有一盏灯,每次只能过两人,于是没过去两个必须回来一个人。<br /> <br />分析:<br />N:总人数,按所花时间从小到大排序:A<B<......<Y<Z,分别对应所用时间a,b......y,z。<br /> <br />分情况讨论:<br />假设数据已经按以上规则排好序。<br /> <br />N=1时,taketime=a;<br /> <br /> A -> a;<br /> <br />N=2时,t原创 2010-08-03 22:49:00 · 623 阅读 · 0 评论 -
Fibonacci 矩阵乘法
斐波那切数列.F(0) = 0, F(1) = 1, F(n) = F(n-1) + F(n-2) (n>=2) 每行输入一个数n和m(n 每行输出F(n)%m. 第 n 个数为:┌ ┐ ^n ┌ ┐ | 0 1 | 0 | 1 1 | 1└ ┘ └原创 2010-05-20 21:34:00 · 770 阅读 · 0 评论 -
第一次完成DFS
http://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原创 2010-05-02 14:30:00 · 390 阅读 · 0 评论 -
进制转换
#include#includeconst char bit[]={"0123456789ABCDEF"}; // 下表对应取余操作得出的值void convert(char * s, int n ,int b){ if(0 == n)// 最后商为0时结束递归 { strcpy( s, ""); return ; } convert(转载 2010-05-02 12:01:00 · 358 阅读 · 0 评论 -
再论字典序
排列下一个字典序: 从原排列后部开始,对相邻一对进行比较,若前者小于后者,标记前者下标为 j;令 k = len - 1, k 递减,寻找到 order[ K ] > order[ j ] (k > j) ,交换两项;对 order[ j + 1 ] 到 order[ k ], 进行从小到大的排序就可以了。 #include #include原创 2010-04-29 21:36:00 · 376 阅读 · 0 评论 -
DP应用
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; //刚开始接触DP题,用起来也很不熟练,看了discuss写的#includeint r原创 2010-04-27 21:35:00 · 419 阅读 · 0 评论 -
对二维字符数组排序(2sort和1qsort)
sort,用到了结构体 第一种sort:282MS#include#includeusing namespace std;struct Array{ char data[30];}dna[20005];bool operator < (Array const& arr1, Array const& arr2){ return strc原创 2010-04-22 22:21:00 · 536 阅读 · 0 评论 -
二叉树重建
摘自刘汝佳的《算法竞赛入门经典》PreOrder(T) = T 的根结点 + PreOrder(T 的左子树) + PreOrder(T 的右子树);InOrder(T) = InOrder(T 的左子树) + T 的根结点 + InOrder(T 的右子树);PostOrder(T) = PostOrder(T 的左子树) + PostOrder(T 的右子树) + T 的根原创 2010-04-22 18:44:00 · 418 阅读 · 0 评论 -
求连续段最大和(dp)
最大的和 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原创 2010-04-21 16:42:00 · 436 阅读 · 0 评论 -
LIS(最长上升子序列)
这是O(n^2)的算法: #includeint main(){ int n,i,k,max,lis[1001],num[1001]; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) { scanf("%d",&num[i]); lis[i]=1; } for(i=1;i<n;i++原创 2010-04-07 13:16:00 · 1699 阅读 · 0 评论 -
求有向面积(多边形面积)
#include#include#define MAX 1001int main(){ int n,i; double x[MAX],y[MAX],dsum; while(scanf("%d",&n)!=EOF) { for(i=0; i<n; i++) scanf("%lf%lf",&x[i],&y[i]); x[n]=x[0]; y[n原创 2010-04-16 23:08:00 · 839 阅读 · 0 评论 -
sort用法
#include#includeusing namespace std;int a[3000001];/*bool cmp(int a, int b){ return a>b; //a>b为从大到小,sort默认从小到大}*/int main (){ int nCase,i; while(scanf("%d", &nCase)+1) {原创 2010-04-12 21:34:00 · 440 阅读 · 0 评论 -
三分
拿这题来说事:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3421 ZOJ Problem Set - 3421Error CurvesTime Limit: 2 Seconds Memory Limit: 65536 KB Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to原创 2010-11-14 12:12:00 · 690 阅读 · 0 评论