- 博客(35)
- 资源 (17)
- 收藏
- 关注
原创 UESTC 方老师与素数
方老师最近很喜欢素数,他想玩一个游戏:现在有两个4位的素数n和m,你一次可以改变n的一位数字,并且改变过后的新数字必须也是个素数,并且也不能有前导0。请问使n变为m最少需要多少步。例如n=1033 m=8179那么可行的变化是:1033173337333739377987798179Input第一行有一个整数T(T≤100),代表测试数据的组数。
2014-10-30 17:17:33 543
原创 UESTC 解救小Q
小Q被邪恶的大魔王困在了迷宫里,love8909决定去解救她。 迷宫里面有一些陷阱,一旦走到陷阱里,就会被困身亡:(,迷宫 里还有一些古老的传送阵,一旦走到传送阵上,会强制被传送到 传送阵的另一头。现在请你帮助love8909算一算,他至少需要走多少步才能解 救到小Q?Input第一行为一个整数T,表示测试数据组数。每组测试数据第一行为两个整数N,M,(1≤N,M≤50
2014-10-30 15:59:55 1163
原创 hdu 1026 Ignatius and the Princess I
Problem DescriptionThe Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166's castle. The castle is a large labyrint
2014-10-29 13:17:48 513
原创 poj 2386 Lake Counting
DescriptionDue to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains
2014-10-27 16:36:38 432
原创 图的单源最短路径SPFA算法
算法大致流程是用一个队列来进行维护。初始时将源加入队列。每次从队列中取出一个元素,并对所有与他相邻的点进行松弛,若某个相邻的点松弛成功,则将其入队。直到队列为空时算法结束。这个算法,简单的说就是队列优化的bellman-ford,利用了每个点不会更新次数太多的特点发明的此算法SPFA——Shortest Path Faster Algorithm,它可以在O(kE)的时间复杂度内求
2014-10-27 00:30:54 665
原创 图的单源最短路径Bellman-Ford算法
Dijkstra算法是处理单源最短路径的有效算法,但它局限于边的权值非负的情况,若图中出现权值为负的边,Dijkstra算法就会失效,求出的最短路径就可能是错的。适用条件&范围:单源最短路径(从源点s到其它所有顶点v);有向图&无向图(无向图可以看作(u,v),(v,u)同属于边集E的有向图);边权可正可负(如有负权回路输出错误提示);
2014-10-26 17:06:22 1017
原创 hdu 5073 Galaxy
Problem DescriptionGood news for us: to release the financial pressure, the government started selling galaxies and we can buy them from now on! The first one who bought a galaxy was Tianming Yun
2014-10-25 19:51:10 535
原创 poj 1129 Channel Allocation
DescriptionWhen a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receiver has a strong signal. However, the channels used by each r
2014-10-24 22:52:41 801
原创 前序线索化二叉树
#include using namespace std;enum PointerTag {Link,Thread}; //Link非线索标记,Thread线索标记typedef struct node{ char data; struct node *rchild; struct node *lchild; PointerTag Ltag
2014-10-24 19:48:59 1253
原创 中序线索化二叉树
先理解图,在看代码。#include using namespace std;typedef struct node{ char data; struct node *rchild; struct node *lchild; int rtag; // rtag=0时,表示Rchild指向该结点的右孩子;为1时,表示rchild指向该结点的线性后继结
2014-10-24 17:02:43 789
原创 hdu 1333 Smith Numbers
Problem DescriptionWhile skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University, noticed that the telephone number of his brother-in-law H. Smith had the follo
2014-10-24 00:36:41 646
原创 poj 2236 Wireless Network
DescriptionAn earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all com
2014-10-23 18:56:49 553
原创 poj 1915 Knight Moves
DescriptionBackground Mr Somurolov, fabulous chess-gamer indeed, asserts that no one else but him can move knights from one position to another so fast. Can you beat him? The Problem Your ta
2014-10-23 14:06:28 530
原创 hdu 2874 Connections between cities(最近公共祖先(LCA))
Problem DescriptionAfter World War X, a lot of cities have been seriously damaged, and we need to rebuild those cities. However, some materials needed can only be produced in certain places. So we
2014-10-22 22:38:56 661
原创 poj 1330 Nearest Common Ancestors(最近公共祖先(LCA))
DescriptionA rooted tree is a well-known data structure in computer science and engineering. An example is shown below: In the figure, each node is labeled with an integer from {1, 2,...,16
2014-10-21 19:40:39 1483
原创 Tarjan离线算法求最近公共祖先(LCA)
Problem DescriptionThere are n houses in the village and some bidirectional roads connecting them. Every day peole always like to ask like this "How far is it if I want to go from house A to house
2014-10-20 18:09:18 734
原创 hdu 3405 World Islands(最小生成树)
Problem DescriptionDubai is a haven for the rich. The government of Dubai finds a good way to make money. They built a lot of artificial islands on the sea and sell them. These islands are shaped
2014-10-19 23:04:55 593
原创 hdu 2122 Ice_cream’s world III(最小生成树)
Problem Descriptionice_cream’s world becomes stronger and stronger; every road is built as undirected. The queen enjoys traveling around her world; the queen’s requirement is like II problem, beauti
2014-10-18 20:02:45 567
原创 扩展欧几里得算法
欧几里得算法欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数。基本算法:设a=qb+r,其中a,b,q,r都是整数,则gcd(a,b)=gcd(b,r),即gcd(a,b)=gcd(b,a%b)。
2014-10-18 14:08:43 18612 3
原创 hdu 4607 Park Visit(树直径)
Problem DescriptionClaire and her little friend, ykwd, are travelling in Shevchenko's Park! The park is beautiful - but large, indeed. N feature spots in the park are connected by exactly (N-1) un
2014-10-18 00:27:36 577
原创 poj 1985 Cow Marathon(树直径)
DescriptionAfter hearing about the epidemic of obesity in the USA, Farmer John wants his cows to get more exercise, so he has committed to create a bovine marathon for his cows to run. The maratho
2014-10-17 23:05:53 626
原创 poj 3083 Children of the Candy Corn
DescriptionThe cornfield maze is a popular Halloween treat. Visitors are shown the entrance and must wander through the maze facing zombies, chainsaw-wielding psychopaths, hippies, and other terro
2014-10-15 22:10:43 459
原创 poj 2488A Knight's Journey
DescriptionBackground The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journeyaround the world. Whenever a knight moves, it is t
2014-10-14 19:09:34 471
原创 hdu 5007 Post Robot
Problem DescriptionDT is a big fan of digital products. He writes posts about technological products almost everyday in his blog.But there is such few comments of his posts that he feels depre
2014-10-12 11:46:12 540
原创 最小生成树prim算法(贪心)
一个连通图的生成树是一个极小的连通子图,它含有图中全部的顶点,但只有足以构成一棵树的n-1条边。所谓的最小成本,就是n个顶点,用n-1条边把一个连通图连接起来,并且使得权值的和最小。综合以上两个概念,我们可以得出:构造连通网的最小代价生成树,即最小生成树(Minimum Cost Spanning Tree)。Prim算法也是利用贪心算法来解决最小生成树。最小生成树MST性
2014-10-09 19:27:49 1558 1
原创 图的单源最短路径Dijkstra算法
单源最短路径问题给定一个带权有向图 G=(V,E) ,其中每条边的权是一个非负实数。另外,还给定 V 中的一个顶点,称为源。现在我们要计算从源到所有其他各顶点的最短路径长度。这里的长度是指路上各边权之和。这个问题通常称为单源最短路径问题。
2014-10-09 00:49:55 1167
原创 wikioi 2549 自然数和分解
题目描述 Description把自然数N分解为若干个自然数之和,输出方案数。输入描述 Input DescriptionN,(1≤n≤50)输出描述 Output Description方案数样例输入 Sample Input5样例输出 Sample Output7
2014-10-08 23:17:25 933
原创 wikioi 2597 团伙
题目描述 Description1920年的芝加哥,出现了一群强盗。如果两个强盗遇上了,那么他们要么是朋友,要么是敌人。而且有一点是肯定的,就是:我朋友的朋友是我的朋友;我敌人的敌人也是我的朋友。 两个强盗是同一团伙的条件是当且仅当他们是朋友。现在给你一些关于强盗们的信息,问你最多有多少个强盗团伙。输入描述 Input Description输入文件
2014-10-05 20:59:09 990
原创 TOJ 3517 The longest athletic track(树直径)
After a long time of algorithm training, we want to hold a running contest in our beautiful campus. Because all of us are curious about a coders's fierce athletic contest,so we would like a more lon
2014-10-05 17:08:41 739
原创 wikioi 1231 最优布线问题
题目描述 Description学校需要将n台计算机连接起来,不同的2台计算机之间的连接费用可能是不同的。为了节省费用,我们考虑采用间接数据传输结束,就是一台计算机可以间接地通过其他计算机实现和另外一台计算机连接。为了使得任意两台计算机之间都是连通的(不管是直接还是间接的),需要在若干台计算机之间用网线直接连接,现在想使得总的连接费用最省,让你编程计算这个最小的费用。
2014-10-04 20:16:15 1298
原创 Wikioi 1069 关押罪犯
题目描述 DescriptionS 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N。他们之间的关系自然也极不和谐。很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突。我们用“怨气值”(一个正整数值)来表示某两名罪犯之间的仇恨程度,怨气值越大,则这两名罪犯之间的积怨越多。如果两名怨气值为c 的罪犯被关押在同一监狱,他们俩之间会发生摩擦,并造成影响力为c 的冲
2014-10-04 19:28:18 886 2
原创 wikioi 1001 舒适的路线
题目描述 DescriptionZ小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光。Z小镇附近共有N(1输入描述 Input Description第一行包含两个正整数,N和M。接下来的M行每行包含三个正整数:x,y和v(1≤x,y≤N,0 最后一行包含两个正整数s,t,表示想知道从景点s到景点t最大最小速度比最小的路径。s和t不可能相同。
2014-10-04 17:01:41 1278
TCP-IP详解卷1:协议
2015-10-15
nasm中文手册
2015-03-12
STL源码剖析简体中文完整版清晰
2014-11-11
C++标准程序库
2014-11-10
ACM培训-动态规划
2014-11-10
取石子游戏_博弈
2014-11-10
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人