赵乐ACM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  103 随笔 :: 0 文章 :: 41 评论 :: 96617 阅读

随笔分类 -  ACM

摘要:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number inCmay only be usedoncein the combination.Note:All numbers (including target) will be positive integers.Elements in a combination (a1,a2, � ,ak) must 阅读全文
posted @ 2013-08-07 15:50 赵乐ACM 阅读(658) 评论(0) 推荐(0) 编辑

摘要:1. 写得最有逻辑的一道题了,10次讲座学的最好的就是DFS和BFS了。2. 直接深搜#include #include #include #include #include #include #include #include #include #include using namespace std; int a, b, sx, sy; char map[25][25]; int num[25][25]; bool flag[25][25]; int dir[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0... 阅读全文
posted @ 2012-07-10 16:25 赵乐ACM 阅读(153) 评论(0) 推荐(0) 编辑

摘要:#include #include #include #include #include #include #include //#include #include #include const int INT_MAX = (1 d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j]; } int main() { int n, j, i, a, b, m; while (cin >> n) { if (!n) break; ... 阅读全文
posted @ 2012-07-10 15:27 赵乐ACM 阅读(137) 评论(0) 推荐(0) 编辑

摘要:定义:除了1和其本身,没有其他约数的数。测试:用n分别试除2到sqrt(n)的数,如果中间有一个能整除,即为合数,否则即为素数bool is_prime(int n)//判断n是否为素数,是素数返回1 { int i; bool flag = 1; for(i = 2; i i)Prime[++q] = i; } } 大范围内筛素数的普通筛法(很慢):#define Max 1000000 int Prime[500000]; bool IsPrime[Max] = {1}; int q; void get_prime() { q = -1; ... 阅读全文
posted @ 2012-07-08 21:54 赵乐ACM 阅读(235) 评论(0) 推荐(0) 编辑

摘要:#include #include #include #include #include #include #include using namespace std; int num[5845]; void f() { int i, j, k, l, temp; i = j = k = l = 2; memset(num, 0, sizeof(num)); num[0] = num[1] = 1; int num1, num2, num3, num4; for (int m = 2; m > n) { if... 阅读全文
posted @ 2012-07-08 14:00 赵乐ACM 阅读(161) 评论(0) 推荐(0) 编辑

摘要:1. 简单的bfs,有用双向bfs的,但是为了赶进度,以后用双向bfs实现#include #include #include #include #include #include #include using namespace std; int dir[8][2] = {{-2, 1}, {-1, 2}, {1, 2}, {2, 1}, {2, -1}, {1, -2}, {-1, -2}, {-2, -1}}; int flag[301][301], step[301][301]; int n, len, i; struct Node { int x, y; } ... 阅读全文
posted @ 2012-07-07 15:13 赵乐ACM 阅读(270) 评论(0) 推荐(0) 编辑

摘要:1. 并查集,有点忘了,看维基百科回顾起来了,三个操作,路径压缩、合并、查找父节点。代码很简单,具体参考http://zh.wikipedia.org/wiki/%E5%B9%B6%E6%9F%A5%E9%9B%862. WA了好多次,最后发现是当空树的时候也是一棵树,fuck。。。#include #include #include #include #include #include #include #define maxn 1000 using namespace std; int p[maxn], flag[maxn]; int getfather(int x) { ... 阅读全文
posted @ 2012-07-07 09:53 赵乐ACM 阅读(125) 评论(0) 推荐(0) 编辑

摘要:图论这块挺不好理解的,建图+最短路,代码不容易理解,尤其是建图过程。以下是转的写的很好地一篇博文,图文并茂:邻接表建图法1极大的节省了空间和时间 是建图非常棒的一种方式它利用数组模拟出边与边之间的关系 图示解析(数据为代码中的测试数据):#include #define Maxn 200 using namespace std; struct edge{int from,to,weight,next;}e[Maxn];//存储边信息的结构体 int first[Maxn];//起点为下标存储(e中边的位置) int main() { int edges;//边数... 阅读全文
posted @ 2012-05-09 15:18 赵乐ACM 阅读(619) 评论(0) 推荐(0) 编辑

摘要:1. 算法:把所有的时间按照开始的时间从小到大排序,然后设当前cur为目前的至少有一个工作的时间段,判断下一个时间段是跟这个时间段交叉还是包含在这个时间段之内还是在这个时间段之外,根据这三种不同过的情况,分别得到答案。值得注意的是,最后要得到cur的时间段的值,因为前边的循环当中,没有判断跟这个时间段比较的情况。以下是代码:/* ID: dollar4 PROG: milk2 LANG: C++ */ #include #include #include #include #include using namespace std; const int MAXN = 5000; st... 阅读全文
posted @ 2012-04-08 16:49 赵乐ACM 阅读(184) 评论(0) 推荐(0) 编辑

摘要:1. 数学题,欧几里得算法,求不定方程的整数解问题;2. 必要的数学知识(转):此题其实就是扩展欧几里德算法-求解不定方程,线性同余方程。 设过s步后两青蛙相遇,则必满足以下等式: (x+m*s)-(y+n*s)=k*l(k=0,1,2....) 稍微变一下形得: (n-m)*s+k*l=x-y 令n-m=a,k=b,x-y=c,即 a*s+b*l=c 只要上式存在整数解,则两青蛙能相遇,否则不能。扩展欧几里德算法是用来在已知a, b求解一组x,y使得a*x+b*y=Gcd(a,b)(解一定存在,根据数论中的相关定理)。扩展欧几里德常用在求解模线性方程及方程组中。下面是... 阅读全文
posted @ 2012-03-31 10:56 赵乐ACM 阅读(225) 评论(0) 推荐(1) 编辑

摘要:1. 模拟题,按照题目的要求做即可,但是要细心,比较繁琐,尤其是边界问题;2. 20分钟写完程序,但是WA了七八次,检查了一个小时,最后加上循环输入输出,居然AC了,欲哭无泪。#include #include #include using namespace std; const int MAXn = 10010; bool cmp(int a, int b) { return a > n >> m) { for (i = 0; i > rmovNum[i]; memset(curList, 0, sizeof(curList)); ... 阅读全文
posted @ 2012-03-30 15:20 赵乐ACM 阅读(182) 评论(0) 推荐(0) 编辑

摘要:1. 简单题,根据题意,这个人总是坐着最先到达的自行车到达,因此只需要算出最先到达的自行车的时间即可。2. 值得注意的是出发时间小于0的,这个人不可能坐上这辆车。#include #include using namespace std; int speed; int stime; double dtime; int main() { int n, min, i; while (cin >> n) { if (n == 0) break; min = 1000000; for (i = 0;... 阅读全文
posted @ 2012-03-29 15:25 赵乐ACM 阅读(111) 评论(0) 推荐(0) 编辑

摘要:1. 简单题#include #include using namespace std; int main() { int n, i, ans, t[11], s; while (cin >> n) { if (n == -1) break; memset(t, 0, sizeof(t)); ans = 0; for (i = 1; i > s >> t[i]; ans += s * (t[i] - t[i-1]); } ... 阅读全文
posted @ 2012-03-29 14:49 赵乐ACM 阅读(191) 评论(0) 推荐(0) 编辑

摘要:1. 简单题,故意用了栈,另外从这个题上可以体会到OJ判题模式#include #include #include using namespace std; int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); stack st; int i, j, n; string str; for (i = 1; ; i++) { cin >> n; if (n == 0) ... 阅读全文
posted @ 2012-03-29 14:34 赵乐ACM 阅读(184) 评论(0) 推荐(0) 编辑

摘要:1. 这道题根本不会做,直接看的别人的解体报告,看了别人的解题报告的算法说明,还是不会做,只好看代码了;2. 这篇博客写得比我写得好(http://jovesky.info/blog/2011/08/12/poj-1057-file-mapping-c-edition/),我就是看人家的看懂的;3. 递归+vector,一层套一层,以后还得看看怎么做的。现在思路会了,但是vector还是不会用,上午刚看了primer还是不会用,另外细节问题很繁琐,日后就是为了学递归也得再做一遍这道题。#include #include #include #include using namespace... 阅读全文
posted @ 2012-03-28 16:52 赵乐ACM 阅读(230) 评论(0) 推荐(0) 编辑

摘要:1. 根本没有思路,看到如下的解释,才明白怎么做: 这个题目很经典的说,O(N^3)的DP。 首先偶们考察这样的题目,简化版: 已知一列数,求任意连续若干个数和的最大值。 SAMPLE: 3 2 -6 2 -1 7 原数3 2 -6 2 -1 7 处理3 5 -1 2 1 8 因为是连续若干个自然数的和,那么,前面的某个数字取与不取的条件在于:以前面这个数字为结尾的连续数的和最大值是否大于0,如果大于0,那么这个数字必然要会出现在包括数字的序列中,否则无法做到最大... 阅读全文
posted @ 2012-03-28 15:31 赵乐ACM 阅读(176) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示