![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
Wanidde
本人很懒,什么都没有留下 ^_^
展开
-
第六届河南省大学生程序设计竞赛—— 异 形 卵(暴力)
问题 A: 异 形 卵题目描述我们探索宇宙,是想了解浩瀚星空的奥妙,但我们却很少意识到宇宙深处藏匿的危险,它们无时无刻不紧盯着我们的地球。如果外星人拜访我们,结果可能与哥伦布当年踏足美洲大陆不会有什么两样,这是历史,也是现实。在ZDM-777星球上发现的休眠异形卵,其外表与常见的卵不同,表面被一层...原创 2019-04-19 10:57:41 · 116 阅读 · 0 评论 -
HDU 1281 - 棋盘游戏 (二分匹配)
小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的“车”,并且使得他们不能互相攻击,这当然很简单,但是Gardon限制了只有某些格子才可以放,小希还是很轻松的解决了这个问题(见下图)注意不能放车的地方不影响车的互相攻击。所以现在Gardon想让小希来解决一个更难的问题,在保证尽量多的“车”的前提下,棋盘里有些格子是可以避开的,也就是说,不在这些格子上放车,也...原创 2018-08-10 11:36:18 · 184 阅读 · 0 评论 -
POJ 1860 - Currency Exchange (正权回路 Bellman - Ford)
Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations only with these currencies. There can...原创 2018-07-28 11:45:56 · 133 阅读 · 0 评论 -
HDU 1068 - Girls and Boys (最大独立集)
the second year of the university somebody started a study on the romantic relations between the students. The relation “romantically involved” is defined between one girl and one boy. For the study r...原创 2018-08-09 15:40:02 · 125 阅读 · 0 评论 -
POJ 3692 - Kindergarten (最大团)
KindergartenTime Limit: 2000MS Memory Limit: 65536K Total Submissions: 7658 Accepted: 3777 DescriptionIn a kindergarten, there are a lot of kids. All girls of the kids know eac...原创 2018-08-09 15:25:06 · 115 阅读 · 0 评论 -
POJ 3026 - Borg Maze (BFS + Prim)
The Borg is an immensely powerful race of enhanced humanoids from the delta quadrant of the galaxy. The Borg collective is the term used to describe the group consciousness of the Borg civilization. E...原创 2018-07-31 11:38:54 · 150 阅读 · 0 评论 -
最小生成树算法(Kruskal 算法 和 Prim算法)
Kruskal算法: 时间复杂度O(MlogM).算法总结: 首先把给的边按照边的权值进行从小到大的排序,每次从剩余的边中选择权值较小且边的两个顶点不在同一个集合内的边(就是不会产生回路的边),加入到生成树中,直到加入了n-1条边为止。完整代码:#include<stdio.h>struct edge{ int u; int v; in...原创 2018-07-31 15:44:38 · 251 阅读 · 0 评论 -
POJ 1062 - 昂贵的聘礼 (dijkstra)
年轻的探险家来到了一个印第安部落里。在那里他和酋长的女儿相爱了,于是便向酋长去求亲。酋长要他用10000个金币作为聘礼才答应把女儿嫁给他。探险家拿不出这么多金币,便请求酋长降低要求。酋长说:"嗯,如果你能够替我弄到大祭司的皮袄,我可以只要8000金币。如果你能够弄来他的水晶球,那么只要5000金币就行了。"探险家就跑到大祭司那里,向他要求皮袄或水晶球,大祭司要他用金币来换,或者替他弄来其他的东西,...原创 2018-07-27 17:14:59 · 111 阅读 · 0 评论 -
HDU 2063 - 过山车 (二分匹配模板题)
RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了。可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐。但是,每个女孩都有各自的想法,举个例子把,Rabbit只愿意和XHD或PQK做partner,Grass只愿意和linle或LL做partner,PrincessSnow愿意和水域浪子或伪酷儿做partner。考虑...原创 2018-08-10 11:41:01 · 168 阅读 · 0 评论 -
HDU 2119 - Matrix (二分匹配最小点集覆盖)
Give you a matrix(only contains 0 or 1),every time you can select a row or a column and delete all the '1' in this row or this column .Your task is to give out the minimum times of deleting all the '...原创 2018-08-10 11:44:22 · 179 阅读 · 0 评论 -
HDU 1253 - 胜利大逃亡 ( dfs )
Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会.魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,现在知道魔王将在T分钟后回到城堡,Ignatius每分钟能从一个坐标走到相邻的六个坐标中的其中一个.现在给你城堡的地图,请你计算出Ig...原创 2018-08-16 11:25:40 · 249 阅读 · 0 评论 -
HDU 1176 - 免费馅饼 (DP)
都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏,虽然在游戏中是个身手敏捷的高手,但在现实中运动神经特别迟钝...原创 2018-08-02 15:31:40 · 153 阅读 · 0 评论 -
二分匹配 (匈牙利算法及模板)
二分匹配我认为其实就是m个女生,n个男生相互认识的在一起,求最大匹配成的对数。 二分匹配的时间复杂度是O(NM)相关概念:最大匹配数:最大匹配的匹配边的数目定理1:最大匹配数 = 最小点覆盖数(这是 Konig 定理) 定理2:最大独立集 = 顶点数 - 最小点覆盖数 定理3:最小路径覆盖数 = 顶点数 - 最大匹配数最大完全数:图中最大完全子图的顶点个数。独立...原创 2018-08-11 09:41:01 · 181 阅读 · 0 评论 -
HDU 3829 - Cat VS Dog(最大独立集)
The zoo have N cats and M dogs, today there are P children visiting the zoo, each child has a like-animal and a dislike-animal, if the child's like-animal is a cat, then his/hers dislike-animal must b...原创 2018-08-10 17:33:21 · 235 阅读 · 0 评论 -
HDU 2159 - FATE (DP)
最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务。久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最后一级。现在的问题是,xhd升掉最后一级还需n的经验值,xhd还留有m的忍耐度,每杀一个怪xhd会得到相应的经验,并减掉相应的忍耐度。当忍耐度降到0或者0以下时,xhd就不会玩这游戏。xhd还说了他最多只杀s只怪。请问他能升掉这最后一级吗?Inp...原创 2018-08-01 19:57:00 · 119 阅读 · 0 评论 -
POJ 2533 - Longest Ordered Subsequence (最长上升子序列)
A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence ( a1, a2, ..., aN) be any sequence ( ai1, ai2, ..., aiK), where 1 <= i1 < i2...原创 2018-08-01 19:47:17 · 128 阅读 · 0 评论 -
HDU 2602 - Bone Collector (背包问题 dp)
Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …The bone collector ...原创 2018-08-01 19:40:09 · 148 阅读 · 0 评论 -
HDU 1171 - Big Event in HDU (多重背包)
Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.Th...原创 2018-08-01 19:34:21 · 121 阅读 · 0 评论 -
HDU 2191 - 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 (01背包)
急!灾区的食物依然短缺!为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。请问:你用有限的资金最多能采购多少公斤粮食呢?后记:人生是一个充满了变数的生命过程,天灾、人祸、病痛是我们生命历程中不可预知的威胁。月有阴晴圆缺,人有旦夕祸福,未来对于我们而言是一个未知数。那么,我们...原创 2018-08-01 19:22:53 · 100 阅读 · 0 评论 -
Hiho 1038 - 01背包(DP)
且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励的时刻了!小Ho现在手上有M张奖券,而奖品区有N件奖品,分别标号为1到N,其中第i件奖品需要need(i)张奖券进行兑换,同时也只能兑换一次,为了使得辛苦得到的奖券不白白浪费,小Ho给每件奖品都评了分,其中第i件奖品的评分值为value(i),表示他对这件奖品的喜好值。现在他想知道,凭借他手上的这些...原创 2018-08-01 17:26:44 · 138 阅读 · 0 评论 -
Hiho 1037 - 数字三角形 (DP)
问题描述小Hi和小Ho在经历了螃蟹先生的任务之后被奖励了一次出国旅游的机会,于是他们来到了大洋彼岸的美国。美国人民的生活非常有意思,经常会有形形色色、奇奇怪怪的活动举办,这不,小Hi和小Ho刚刚下飞机,就赶上了当地的迷宫节活动。迷宫节里展览出来的迷宫都特别的有意思,但是小Ho却相中了一个其实并不怎么像迷宫的迷宫——因为这个迷宫的奖励非常丰富~于是小Ho找到了小Hi,让小Hi帮助他获取尽可能...原创 2018-08-01 17:24:15 · 158 阅读 · 0 评论 -
最短路的四种的求解方法+模板
一、Floyd算法: Floyd算法只有五行代码,代码简单,三个for循环就可以解决问题,所以它的时间复杂度为O(n*n*n),可以求多源最短路问题。 Floyd算法可以处理带有负权边,但不能处理带有“负权回路”的图。核心代码:for(k=1;k<=n;k++) for(i=1;i<=n;i++) for(j=1;j<=n;j...原创 2018-07-28 09:18:12 · 3234 阅读 · 0 评论 -
HDU 1867 - A + B for you again (KMP)
Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the addition between ...原创 2018-07-23 09:33:17 · 181 阅读 · 0 评论 -
POJ 2031 - Building a Space Station (Prim 最小生成树)
You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write a computer program to complete the task.The space...原创 2018-07-29 21:27:17 · 154 阅读 · 0 评论 -
最小生成树一·Prim算法 (模板题)
描述最近,小Hi很喜欢玩的一款游戏模拟城市开放出了新Mod,在这个Mod中,玩家可以拥有不止一个城市了!但是,问题也接踵而来——小Hi现在手上拥有N座城市,且已知这N座城市中任意两座城市之间建造道路所需要的费用,小Hi希望知道,最少花费多少就可以使得任意两座城市都可以通过所建造的道路互相到达(假设有A、B、C三座城市,只需要在AB之间和BC之间建造道路,那么AC之间也是可以通过这两条道路连...原创 2018-07-29 21:19:59 · 3081 阅读 · 0 评论 -
最小生成树二·Kruscal算法(模板题)
描述随着小Hi拥有城市数目的增加,在之间所使用的Prim算法已经无法继续使用了——但是幸运的是,经过计算机的分析,小Hi已经筛选出了一些比较适合建造道路的路线,这个数量并没有特别的大。所以问题变成了——小Hi现在手上拥有N座城市,且已知其中一些城市间建造道路的费用,小Hi希望知道,最少花费多少就可以使得任意两座城市都可以通过所建造的道路互相到达(假设有A、B、C三座城市,只需要在AB之间和...原创 2018-07-29 21:18:06 · 285 阅读 · 0 评论 -
HDU 1102 - Constructing Roads ( Prim 最小生成树 )
There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if and only if t...原创 2018-07-29 21:16:03 · 170 阅读 · 0 评论 -
HDU 2717 - Catch That Cow (BFS)
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,0...原创 2018-07-20 17:43:45 · 186 阅读 · 0 评论 -
HDU 2544 - 最短路 (Floyd 最短路)
在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗? Input输入包括多组数据。每组数据第一行是两个整数N、M(N<=100,M<=10000),N表示成都的大街上有几个路口,标号为1的路口是商店所在地,标号为N的路口是...原创 2018-07-25 14:44:39 · 117 阅读 · 0 评论 -
HDU 1874 - 畅通工程续 (Floyd 最短路)
某省自从实行了很多年的畅通工程计划后,终于修建了很多路。不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多。这让行人很困扰。现在,已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离。Input本题目包含多组数据,请处理到文件结束。每组数据第一行包含两个正整数N和M(0<N<200,0<M...原创 2018-07-25 14:41:43 · 182 阅读 · 0 评论 -
博弈问题
一、尼姆博奕(Nimm Game): 有N堆石头,每堆石头数目在1到100之间,最多有10堆.两人分别取走石头.取石头的规则是:每次只能从1堆中取,每次取走至少1个。取过后还可以把这堆的石头任意分配到其它石子数不为0的堆上,当然也可以不分配。问给定这些石头堆的情况,两人轮流取,谁取走最后一个石子谁胜利,问是先取的胜利还是后取的胜利.双方最优策略。 POJ - 2234...原创 2018-07-19 11:46:37 · 526 阅读 · 0 评论 -
HDU 1527 - 取石子游戏 (威佐夫博奕(Wythoff Game))
有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者。Input输入包含若干行,表示若干种石子的初始情况,其中每一行包含两个非负整数a和b,表示两堆石...原创 2018-07-19 11:13:54 · 125 阅读 · 0 评论 -
POJ 2234 - Matches Game (尼姆博奕(Nimm Game))
Here is a simple game. In this game, there are several piles of matches and two players. The two player play in turn. In each turn, one can choose a pile and take away arbitrary number of matches from...原创 2018-07-19 10:31:23 · 210 阅读 · 0 评论 -
POJ 1740 - A New Stone Game (Nim博弈变形)
Alice and Bob decide to play a new stone game.At the beginning of the game they pick n(1<=n<=10) piles of stones in a line. Alice and Bob move the stones in turn.At each step of the game,the pl...原创 2018-07-19 10:18:16 · 168 阅读 · 0 评论 -
POJ 1258 - Agri-Net (Prim最小生成树)
Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course.Farmer John ordered a high spee...原创 2018-07-29 21:30:17 · 147 阅读 · 0 评论 -
关于搜索(DFS 、BFS)
深度优先搜索(DFS): 思想: 首先以一个未被访问过的顶点作为开始顶点,沿当前顶点的边走到未访问过的顶点;当没有未访问过的顶点时,则回溯到上一个顶点,继续试探访问别的顶点,直到所有的顶点都被访问过。完整代码:#include<stdio.h>int a[10],book[10],n;void dfs(int step){ int ...原创 2018-07-21 16:09:38 · 187 阅读 · 0 评论 -
POJ 1751 - Highways (Prim)
The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor system of public highways. The Flatopian government is aware of this problem and has already constructed a numb...原创 2018-07-30 09:41:59 · 138 阅读 · 0 评论 -
POJ 1797 - Heavy Transportation (最短路变形 Dijkstra)
BackgroundHugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his cust...原创 2018-07-27 14:46:50 · 260 阅读 · 0 评论 -
POJ 2349 - Arctic Network (最小生成树 Prim)
The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every o...原创 2018-07-30 17:32:45 · 146 阅读 · 0 评论 -
POJ 1789 - Truck History (最小生成树 Prim)
Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of a tr...原创 2018-07-30 17:22:10 · 122 阅读 · 0 评论