上一页 1 ··· 4 5 6 7 8 9 10 下一页
摘要: 题意描述: john现有h个小时的空闲时间,他打算去钓鱼。john钓鱼的地方共有n个湖,所有的湖沿着一条单向路顺序排列(john每在一个湖钓完鱼后,他只能走到下一个湖继续钓), john必须从1号湖开始钓起,但是他可以在任何一个湖结束他此次钓鱼的行程。john在每个湖中每5分钟钓的鱼数(此题中以5分钟作为单位时间),随时间的增长而线性递减。而每个湖中头5分钟可以钓到的鱼数以及每个湖中相邻5分钟钓鱼数的减少量,input中均会给出。并且John从任意一个湖走到它下一个湖的时间input中也都给出。问题: 求一种方案,使得john在有限的h小时中可以钓到尽可能多的鱼。 output中需包... 阅读全文
posted @ 2010-12-14 18:55 yangleo 阅读(842) 评论(0) 推荐(0) 编辑
摘要: 8题只做出4题比较easy的题,而且做得挺麻烦,看来还要多练练。AC的题如下NEUOJ 1112I Love AppleDescriptionSo many people love apple and there is a problem about apple.An Apple Word is a word that consists of only the letters A, P, L, and E, in that exact relative order. There must be exactly one A, two or more Ps, exactly one L and.. 阅读全文
posted @ 2010-12-12 19:34 yangleo 阅读(414) 评论(0) 推荐(0) 编辑
摘要: 8题只做出4题比较easy的题,而且做得挺麻烦,看来还要多练练。AC的题如下NEUOJ 1112I Love AppleDescriptionSo many people love apple and there is a problem about apple.An Apple Word is a word that consists of only the letters A, P, L, and E, in that exact relative order. There must be exactly one A, two or more Ps, exactly one L and.. 阅读全文
posted @ 2010-12-12 19:34 yangleo 阅读(231) 评论(0) 推荐(0) 编辑
摘要: ///这题不是很理解有待于重做,BFS+模拟,模拟有点麻烦 #include<stdio.h> #include<string.h> #include<queue> using namespace std; queue<int> q; int w,h; char map[45][45]; int dl[4][2]={{0,-1},{-1,0},{0,1},{1,0}}; int vis[45][45]; int dire,k;///指向当前移动方向。 int left(int a,int b,int c,int d) { if(a==c& 阅读全文
posted @ 2010-12-11 21:44 yangleo 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 数塔问题的变形,每一层代表一秒,但要注意下一秒到这一秒,除了左右外还有自己本身这个位置,不能忽略即dp[i][j]=max{dp[i+1][j-1],dp[i+1][j],dp[i+1][j+1]}#include <iostream>using namespace std;int dp[100002][12];int max(int a,int b){ return a>b?a:b;}int main(){ int n,i,j,maxt; int x,t; while(scanf("%d",&n),n!=0) { maxt = 0; memset 阅读全文
posted @ 2010-12-11 21:18 yangleo 阅读(170) 评论(0) 推荐(0) 编辑
摘要: HDU 1159 最长公共子序列问题详见杭电刘春英老师PPT//DP算法://用f[i][j] 表示字符串a的第i个字母与字符串b的第j个字母比较,得到两串相比时第i和第j个字母之前相同字母的个数// 如果a[i-1]==b[j-1], f(i,j)= f(i-1,j-1)+1;否则,f(i,j)=max(f(i,j-1),f(i-1,j));#include<iostream>#include<string>using namespace std;int main(){ int f[500][500]; char a[500],b[500]; int i,j,lena 阅读全文
posted @ 2010-12-11 20:46 yangleo 阅读(291) 评论(0) 推荐(0) 编辑
摘要: 第一道背包问题,0-1背包,参考网上一位大牛写的做的。状态方程:dp[i][w] = max{dp[i-1][w], dp[i-1][w-obj[i].wei] + obj[i].val]},但这样会超内存,需要一个空间复杂度的优化将dp改为一维,这招看来以后得常用,具体见转载的《背包九讲》。 明天好好读读《背包九讲》,在多做几道dp变形题,练习在于精不在多。#include <iostream>using namespace std;const int mMax = 3500;//待选物品个数const int nMax = 14000;//最大容量struct{ int wei 阅读全文
posted @ 2010-11-30 23:57 yangleo 阅读(316) 评论(0) 推荐(0) 编辑
摘要: 这题是水题,主要是用到了C++字符串和cmath中的pow函数。 最近课程有点多,做POJ时间不够,还是要抓紧一些,尤其是动态规划、搜索题等要多练。#include <iostream>#include <string>#include <cmath>using namespace std;int main(){ string s; while(1){ cin>>s; if (s == "0") break; long result = 0; int k = 1; string::iterator it; for (it = 阅读全文
posted @ 2010-11-30 22:24 yangleo 阅读(317) 评论(0) 推荐(0) 编辑
摘要: 今天主要是学习了一下DP,三个使用前提:最优子结构、子问题重叠性、无后效性,今后重点练dp题,至少做30题加深理解 这题纯粹为了练习编码速度。#include <iostream>#include <string>using namespace std;int main(){ int c,miles = 0; string a; char b; while(cin>>a && a[0] != '#'){ if (a[0] != '0') { cin>>a>>c>>b; swi 阅读全文
posted @ 2010-11-28 21:33 yangleo 阅读(248) 评论(0) 推荐(0) 编辑
摘要: 这题很简单,可以设置结构体保存三维及姓名,求出体积最大的人和最小的人输出即可。 由于没有注意输出"."而贡献了一次WA,囧#include <iostream>#include <algorithm>#include <string>using namespace std;struct stu{ stu(){} string name; int d;}s[1000];int comp(const void * a,const void * b){ return ((stu*)a)->d - ((stu*)b)->d;}int 阅读全文
posted @ 2010-11-27 20:47 yangleo 阅读(232) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 下一页