
算法
文章平均质量分 78
Kuro同学
这个作者很懒,什么都没留下…
展开
-
POJ 1679 The Unique MST 判断最小生成树是否唯一/次小生成树
题目链接:1679题意:给出 M个点N条边 求它的的最小生成树 不唯一则输出:Not Unique!题解:prim:判断“最小生成树是否唯一”可以理解为“最小生成树和次小生成树是否相等”求次小生成树的步骤如下1)先求出最小生成树T,在prim的同时,用一个矩阵maxx[u][v]记录在树中连接u-v的路径中权值最大的边.原创 2015-01-26 11:07:53 · 1079 阅读 · 0 评论 -
POJ 1122 FDNY to the Rescue! 反向dijkstra
链接:1122题意:一个城市中有N个交叉路口,给出从一个交叉路口i到另一个交叉路口j所需要的时间(i,j=1~N,单向)如果edge[i][j]=-1 则表示不通给出一个火警的位置(终点) 和X个消防站(起点) 输出:每一行描述了一个消防站的信息,这些信息按消防站到达火警位置所需时间从小到大排列。这些信息包括:消防站的原创 2015-01-27 15:54:37 · 1143 阅读 · 0 评论 -
poj1511||hdu1535 Invitation Cards spfa
题目链接:Invitation Cards题意:给出一个M个点N条边的单向图 1 题解:1 代码:#include#include#include#include#define maxx 0x3f3f3f3fusing namespace std;struct node{原创 2015-01-30 16:45:03 · 895 阅读 · 0 评论 -
ZOJ3088 Easter Holidays spfa 最长路 最短路 路径打印
题目链接:3088题意:一个滑雪胜地包含了n 个地点,m 个滑雪斜坡,k 架雪橇,其中2≤n≤1000、1≤m≤1000、1≤k≤1000。滑雪斜坡和雪橇总是从一个地点到另一个地点:滑雪斜坡是从高地点到低地点,而雪橇刚好相反(注意,雪橇不能下降)。Per 是一个滑雪初学者,他很害怕雪橇,尽管他想滑得尽可能快。现在,他发现他可以选择不同的雪橇和滑雪斜坡。他现在原创 2015-02-01 13:43:05 · 1055 阅读 · 0 评论 -
zoj 3103 Cliff Climbing 优先队列+BFS
题目链接:3103题意:一块N X M 的墙壁,求从S点出发 到T点的最短时间 每次只能爬一步,且只能左右脚交替爬行,墙上每个方块中的数字标明方块的"光滑等级",标有数字t 的方块将花费他t 个单位时间安全地将他的脚踏在上面。题解:队列结构体中有4个变量(x,y,步数,固定的脚(0左脚,1右脚))。将所有s点原创 2015-02-04 21:23:35 · 1062 阅读 · 0 评论 -
NOIP 2002 马拦过河卒 BFS+递推
Description :如图,A点有一个过河卒,需要走到目标B点。卒行走的规则:可以向下、或者向右。同时在棋盘上的任一点有一个对方的马(如上图的C点),该马所在的点和所有跳跃一步可达的点称为方马的控制点。例如上图C点上的马可以控制9个点(图中的P1,P2...P8和C)。卒不能通过对方的控制点。棋盘用坐标表示,A点(0,0)、B点(n, m)(n,m为不超过20的整数,并原创 2014-11-27 13:09:31 · 3138 阅读 · 1 评论 -
POJ 1659 Frogs' Neighborhood 可图性判断-Havel定理
Description未名湖附近共有N个大小湖泊L1, L2, ..., Ln(其中包括未名湖),每个湖泊Li里住着一只青蛙Fi(1 ≤i ≤ N)。如果湖泊Li和Lj之间有水路相连,则青蛙Fi和Fj互称为邻居。现在已知每只青蛙的邻居数目x1,x2, ..., xn,请你给出每两个湖泊之间的相连关系。Input第一行是测试数据的组数T(0 ≤ T ≤ 20)。每原创 2015-01-12 15:28:32 · 970 阅读 · 0 评论 -
poj1020 Anniversary Cake 搜索
DescriptionNahid Khaleh decides to invite the kids of the "Shahr-e Ghashang" to her wedding anniversary. She wants to prepare a square-shaped chocolate cake with known size. She asks each invited pe原创 2015-01-15 08:58:03 · 1068 阅读 · 0 评论 -
hdu1198 Farm Irrigation dfs
Problem DescriptionBenny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot of samll squares. Water pipes are placed in these squares. Different square has原创 2015-01-15 16:57:14 · 1028 阅读 · 0 评论 -
POJ 1094 Sorting It All Out 拓扑排序
DescriptionAn ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from smallest to largest. For example, the sorted sequence原创 2014-11-04 16:50:32 · 764 阅读 · 0 评论 -
UVA 11991 Easy Problem from Rujia Liu? STL MAP的进阶用法
Easy Problem from Rujia Liu?Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 2006, Beijing 2007 and Wuhan 2009, or UVa OJ contests like Rujia Liu's原创 2014-09-25 21:09:06 · 858 阅读 · 0 评论 -
POJ 3254 Corn Fields DP 状态压缩 入门
DescriptionFarmer John has purchased a lush new rectangular pasture composed of M byN (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of square原创 2014-09-23 15:46:49 · 1178 阅读 · 0 评论 -
HDU1426 数独游戏 搜索
Problem Description自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视。据说,在2008北京奥运会上,会将数独列为一个单独的项目进行比赛,冠军将有可能获得的一份巨大的奖品———HDU免费七日游外加lcy亲笔签名以及同hdu acm team合影留念的机会。所以全球人民前仆后继,为了奖品日夜训练茶饭不思。当然也包括初学者li原创 2014-09-12 18:53:16 · 1038 阅读 · 0 评论 -
关于c语言中的位运算。。。
位运算是一种针对二进制数的一种运算位运算 共有六种都有其对应得操作符号& (and) 位于| (or) 位或~ (not) 取反^ (xor) 异或>> (shr) 右移一位运算说明:=== 1. and原创 2014-08-04 16:51:02 · 1280 阅读 · 0 评论 -
POJ 2485 Highways 最小生成树 (Kruskal)
DescriptionThe island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem原创 2014-07-22 14:49:58 · 1409 阅读 · 0 评论 -
Codeforces Round #257 (Div. 2) B Jzzhu and Sequences
Jzzhu has invented a kind of sequences, they meet the following property:You are given x and y, please calculate fn modulo1000000007 (109 + 7).InputThe first line contains two integers原创 2014-07-20 10:27:14 · 1133 阅读 · 0 评论 -
POJ 1328 Radar Installation 贪心
DescriptionAssume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, l原创 2014-07-15 13:12:01 · 719 阅读 · 0 评论 -
hdu2063 过山车 二分匹配
RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了。可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐。但是,每个女孩都有各自的想法,举个例子把,Rabbit只愿意和XHD或PQK做partner,Grass只愿意和linle或LL做partner,PrincessSnow愿意和水域浪子或伪酷儿做partner。考虑原创 2014-07-10 18:40:29 · 857 阅读 · 0 评论 -
HDU 1823 Luck and Love 二维线段树
Problem Description世界上上最远的距离不是相隔天涯海角而是我在你面前可你却不知道我爱你 ―― 张小娴前段日子,枫冰叶子给Wiskey做了个征婚启事,聘礼达到500万哦,天哪,可是天文数字了啊,不知多少MM蜂拥而至,顿时万人空巷,连扫地的大妈都来凑热闹来了。―_―|||由于人数太多,Wiskey实在忙不过来,就把统计的事情全原创 2014-08-07 17:06:33 · 1250 阅读 · 0 评论 -
POJ 1703 Find them, Catch them 并查集
DescriptionThe police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to i原创 2014-07-14 16:46:17 · 632 阅读 · 0 评论 -
POJ2935 Basic Wall Maze bfs记录路径
链接: POJ2935题意:6 X 6的地图 格子和格子可能有墙 整个地图中有三道墙 求起点起点到终点的路径本题中的墙可以理解为某a位置的X方向不能走 即用一个三维数组map[x][y][z]表示(x,y)的Z方向不能走关于记录路径可以用一个pre数组记录每个坐标的前一个坐标的复合值 最后倒序输出方向即可原创 2015-01-20 15:09:46 · 1102 阅读 · 0 评论 -
NOIP2002 产生数
题目描述给出一个整数n(n30) 和k个变换规则(k规则: 一位数可变换成另一个一位数: 规则的右部不能为零。 例如:n=234。有规则(k=2): 2->5 3->6 上面的整数234经过变换后可能产生出的整数为(包括原数):原创 2014-11-25 12:34:56 · 4754 阅读 · 2 评论 -
ZOJ1456 Minimum Transport Cost 用floyd记录路径
These are N cities in Spring country. Between each pair of cities there may be one transportation track or none. Now there is some cargo that should be delivered from one city to another. The transpor原创 2014-10-20 11:27:19 · 991 阅读 · 0 评论 -
POJ 3268 Silver Cow Party 最短路 dij
DescriptionOne cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirecti原创 2014-09-29 11:14:07 · 703 阅读 · 0 评论 -
HDU 1087 Super Jumping! Jumping! Jumping! 最大子序列的和
Problem DescriptionNowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to yo原创 2014-08-04 16:08:00 · 1053 阅读 · 0 评论 -
HDU 3549 Flow Problem 网络流入门
Network flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph. InputThe first line of input contains an in原创 2014-07-11 17:29:44 · 860 阅读 · 0 评论 -
HDU1312 Red and Black 搜索
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can'原创 2014-07-06 19:26:50 · 700 阅读 · 0 评论 -
任意N个数的子集生成算法
第一种方法:#include#include#include#includeusing namespace std;int q[100];int w[100];int cmp(int a,int b){ return a<b;}void subset(int cur,int end){ int i; for(i=0;i<cur;i++)原创 2014-11-30 15:41:39 · 1919 阅读 · 1 评论 -
ZOJ 1913 Euclid's Game 博弈论
题目描述小明和小红在玩欧几里得游戏。他们从两个自然数开始,第一个玩家小明,从两个数的较大数中减去较小数的尽可能大的正整数倍,只要差为非负即可。然后,第二个玩家小红,对得到的两个数进行同样的操作,然后又是小明。就这样轮流进行游戏,直至某个玩家将较大数减去较小数的某个倍数之后差为0为止,此时游戏结束,该玩家就是胜利者。输入格式输入包含多组测试数据。每组输入两个正整数,表示游戏一开始的两个数原创 2014-11-01 12:06:20 · 1339 阅读 · 0 评论 -
HDU 2544 最短路 SPFA 邻接表 模板
Problem Description在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗? Input输入包括多组数据。每组数据第一行是两个整数N、M(N输入保证至少存在1条商店到赛场的路线。 O原创 2014-10-22 12:45:43 · 1059 阅读 · 1 评论 -
HDU 1003 Max Sum 最大连续子序列的和
Problem DescriptionGiven a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 +原创 2014-08-04 15:58:55 · 1049 阅读 · 0 评论 -
HDU 2102 A计划 双层BFS
Problem Description可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位原创 2014-07-29 09:40:09 · 1075 阅读 · 0 评论 -
HDU 1874 畅通工程续 最短路径入门(dijkstra)
Problem Description某省自从实行了很多年的畅通工程计划后,终于修建了很多路。不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多。这让行人很困扰。现在,已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离。 Input本题目包含多组数据,请处理到文件结束。每组数据第一行包原创 2014-07-22 15:56:33 · 1194 阅读 · 0 评论 -
poj2524 Ubiquitous Religions 并查集入门
DescriptionThere are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your un原创 2014-07-14 10:15:48 · 735 阅读 · 0 评论 -
POJ 3083 Children of the Candy Corn (bfs+dfs)
The 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 terrors on their que原创 2014-07-07 16:03:05 · 786 阅读 · 0 评论 -
POJ 3687 Labeling Balls 逆向拓扑排序
链接:poj3687题意:有N个标号为1~N的小球,重量(不包括断言)依次增加 ,现给出M句断言 ,断言格式为a b表示小球a轻于小球b 要求根据重量大小依次输出1~N号小球应在的的位置(重量递增)不满足断言则输出-1题解:因为重量是依次增加的 不能按常规的构造edge[a][b]=1生成拓扑排序既然关系格式和一般拓扑排序是相反的原创 2015-01-22 10:51:55 · 904 阅读 · 0 评论 -
hdu 1251 统计难题 初识map
Problem DescriptionIgnatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). Input输入数据的第一部分是一张单词表,每行一个单词,单词的长度不超过10,它们代表的是老师交给Ignatius统计的单词,一个空行代表单词表的结束原创 2014-08-30 15:27:53 · 1031 阅读 · 0 评论 -
POJ 1579 Function Run Fun 记忆化搜索
DescriptionWe all love recursion! Don't we?Consider a three-parameter recursive function w(a, b, c):if a 1if a > 20 or b > 20 or c > 20, then w(a, b, c) returns:w(20, 20, 20)if a原创 2014-08-27 15:06:31 · 1020 阅读 · 0 评论 -
HDU 1166 敌兵布阵 线段树
Problem DescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。原创 2014-08-06 09:25:08 · 1006 阅读 · 0 评论 -
POJ 1915 Knight Moves 双向BFS 入门
DescriptionBackgroundMr 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 ProblemYour task is原创 2014-07-30 20:50:42 · 1189 阅读 · 0 评论