赵乐ACM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
上一页 1 2 3 4 5 6 7 8 9 ··· 11 下一页

2012年7月8日

摘要: 定义:除了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 阅读(230) 评论(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 阅读(158) 评论(0) 推荐(0) 编辑

2012年7月7日

摘要: 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 阅读(268) 评论(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 阅读(122) 评论(0) 推荐(0) 编辑

2012年5月22日

摘要: 1. 识别6G内存由于现在电脑是6G内存,所以需要用apt内核来识别,在新立得软件包里搜索linux-image,找到linux-image-apt,安装即可。有命令行形式,第一次可以,第二次重装之后就会出错,所以这里还是不记下来了。2. 修改网卡物理地址 可以在网络连接,eth0->编辑->克隆地址里填入你要改到物理地址,然后把上边到一行删掉3. 修改hosts学校可以用ipv6FQ看youtube。hosts在 /etc/hosts下4. 安装code::blocks直接在软件包里下载安装。值得注意的是还需要配置下面让codeblocks调用系统终端:启动codeblocks, 阅读全文
posted @ 2012-05-22 20:37 赵乐ACM 阅读(392) 评论(0) 推荐(0) 编辑

2012年5月9日

摘要: 图论这块挺不好理解的,建图+最短路,代码不容易理解,尤其是建图过程。以下是转的写的很好地一篇博文,图文并茂:邻接表建图法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 阅读(607) 评论(0) 推荐(0) 编辑

2012年4月24日

摘要: 1. 第一次做位运算的题,参考了这段经典代码(n皇后问题):void Queen(int row, int ld, int rd) { int pos, p; int upperlim = (1 > 1); } } else ++sum; }2. 以下是代码:/* ID: dollar4 PROG: checker LANG: C++ */ #include #include #include #include #include #include #include using namespace std; ofstream fou... 阅读全文
posted @ 2012-04-24 16:24 赵乐ACM 阅读(177) 评论(0) 推荐(0) 编辑

摘要: 1.从数学的角度: 1.首位只能是质数2 3 5 72.其余位只能是1,3,7,93.若n=1,直接输出2,3,5 7直接DFS 1~9,加入当前数末尾,并判断是不是素数,是则递归处理下一位数,不是则回溯,直到depth>n。不会超时。2. 这道题折磨了我好久,一直出现Execution error: Your program (`sprime') exited with signal #11 (segmentation violation [maybe caused by accessing memory out of bounds, array indexing out of 阅读全文
posted @ 2012-04-24 16:19 赵乐ACM 阅读(195) 评论(0) 推荐(0) 编辑

2012年4月21日

摘要: 1. 无数遍TLE的题,快疯了,最后没办法,只能看别人的代码,最好的一个代码,写了下来,但是还有一点地方不太明白,这是一种新的方法,以下是代码/* ID: dollar4 PROG: pprime LANG: C++ */ #include #include #include #include #include using namespace std; int modify(int x) { int t = x; x /= 10; while (x > 0) { t = t * 10 + x % 10; x /= 10... 阅读全文
posted @ 2012-04-21 21:56 赵乐ACM 阅读(192) 评论(0) 推荐(0) 编辑

2012年4月17日

摘要: 1. 动态规划,f[i,j]=Max{f[i+1,j],f[i+1,j+1]}+a[i,j] (1 #include #include #include #include using namespace std; long long num[1010][1010]; long max(long a, long b) { if (a > b) return a; else return b; } int main() { ofstream fout ("numtri.out"); ifstream fin ("numtri.in"); ... 阅读全文
posted @ 2012-04-17 17:26 赵乐ACM 阅读(241) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 9 ··· 11 下一页