上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 21 下一页
摘要: 题目链接详细请参考刘汝佳《算法竞赛入门经典训练指南》 p67//2013-05-01-20.40//uva 10891#include #include #include using namespace std;const int maxn = 105;bool vis[maxn][maxn];int s[maxn];int d[maxn][maxn];int dp(int i, int j){ if (vis[i][j]) return d[i][j]; vis[i][j] = true; int m = 0; for (int k = i+1; k <... 阅读全文
posted @ 2013-05-27 20:56 xindoo 阅读(136) 评论(0) 推荐(0) 编辑
摘要: A. Whose sentence is it?代码://codeforces 312 A//2013-05-01-19.12#include #include char str[102];int main(){ int n; scanf("%d", &n); getchar(); while (n--) { int f = 0; int r = 0; gets(str); int l = strlen(str); if (str[0] == 'm' && str[1] == 'i' && st... 阅读全文
posted @ 2013-05-27 19:17 xindoo 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 题目链接//hdoj 4551//2013-05-26-20.52#include int day[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};int judge(int y){ if (y%4 == 0 && y % 100 != 0 || y % 400 == 0) return 1; else return 0;}int gcd(int x, int y){ if (x%y == 0) re... 阅读全文
posted @ 2013-05-26 20:49 xindoo 阅读(131) 评论(0) 推荐(0) 编辑
摘要: //hdoj 4554//2013-05-26-19.47#include int turn(int x){ int f = 1; if (x >1; int b = x-a; a = turn(a); b = turn(b); printf("%d %d\n", a+b, a-b); } return 0;} 阅读全文
posted @ 2013-05-26 19:43 xindoo 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 题目链接有n首歌,编号从1到n,每首歌播放时间为t,播放次数为c,n首歌按次序播放,有m个询问,输出第v分钟正在播放的歌曲编号。很简单的二分查找,直接贴代码。//2013-05-23-20.26#include #include using namespace std;const int maxn = 100005;int sum[maxn];int binary_search(int l, int r, int v){ int mid = (l+r)>>1; if (l == r) return l; if (v > sum[mid]) retu... 阅读全文
posted @ 2013-05-23 20:29 xindoo 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 题目链接输入两个字符串s和t,判断是否可以从t中删除0个或多个字符(其他字符顺序不变),得到字符串是。代码://2013-05-22-07.47#include #include const int maxn = 100005;char s[maxn], t[maxn];int main(){ while (scanf("%s %s", s, t) != EOF) { int l1 = strlen(s); int l2 = strlen(t); int j = 0; for (int i = 0; i < l2 && j <... 阅读全文
posted @ 2013-05-22 07:58 xindoo 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 题目链接题意: 有n个正整数组成的序列,给定一个整数s,求长度最短的连续序列,使他们的和大于或等于s。 关于这个题目,有多种的解法,如果枚举起点和终点,时间复杂度为O(n^3),但如果我们用一个数组B把一段数的和存起来,B[i] = sum(a[1].....a[i])。这样就可以把时间复杂度降到O(n^2)。 还有更好的方法,因为B数组是递增的,我们只需要枚举终点,然后二分查找起点即可,时间复杂度进一步降到O(n*logn),但我们可以继续优化,由于B[i]-s是递增的,枚举的起点也是递增的,换句话说,满足条件的位置也是递增的,因此我们可以怎么写代码://2013-05-21-20.3... 阅读全文
posted @ 2013-05-21 12:42 xindoo 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 题目链接刘汝佳算法竞赛经典入门训练指南p42代码1:#include #include #include using namespace std;int next(int n, int k){ stringstream ss; ss n) s = s.substr(0, n); int ans = 0; stringstream ss2(s); ss2 >> ans; return ans;}int main(){ int t; int n, k; cin>>t; while (t--) { cin... 阅读全文
posted @ 2013-05-20 10:36 xindoo 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 隐藏▲查论编排序算法理论计算复杂性理论大O符号全序关系列表稳定性比较排序自适应排序排序网络整数排序交换排序冒泡排序鸡尾酒排序奇偶排序梳排序侏儒排序快速排序臭皮匠排序Bogo排序选择排序选择排序堆排序Smooth排序笛卡尔树排序锦标赛排序循环排序插入排序插入排序希尔排序二叉查找树排序图书馆排序Patience排序归并排序归并排序梯级归并排序振荡归并排序多相归并排序Strand排序分布排序美国旗帜排序珠排序桶排序爆炸排序计数排序鸽巢排序相邻图排序基数排序闪电排序插值排序并发排序双调排序器Batcher归并网络两两排序网络混合排序Tim排序内省排序Spread排序反移排序J排序其他拓扑排序煎饼排序意 阅读全文
posted @ 2013-05-19 14:43 xindoo 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 题目链接 这两个题目是一样的,大概题意是有3个操作 add x, 在集合中加入x, del x 是删除x, sum 是求出由小到大排序后所有下标mod5等于3的数的和。 这个在hdoj上面,这个题给的时间比较多10s,我用了stl 里的vector和lower_bound, lower_bound 它的作用是返回不小于x的第一个数的位置,这样我们每次插入后就能保证他有序。 最终耗时6234MS,而这种方法在codeforces上超时了,cf只给了3000ms,这道题的标准做法是用线段树。先给出stl的做法//2013-05-18-20.17// hdoj 4288 cf 85d#include 阅读全文
posted @ 2013-05-18 20:38 xindoo 阅读(176) 评论(0) 推荐(0) 编辑
上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 21 下一页