![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
hdu
文章平均质量分 59
Allianzcortex
这个作者很懒,什么都没留下…
展开
-
hdu_1016_素数圈
这道题本来是要考验DFS的,但自己偷懒用STL写,果然TLE,明天再继续完成。#include #include #include #include #include using namespace std; const int maxn=1000; int prime(int n) { for(int i=2;i<=sqrt(float(n));i++) if(n%i=原创 2014-12-15 20:59:54 · 654 阅读 · 0 评论 -
并查集详解_兼_hdu_1232_畅通工程
并查集是一个非常巧妙的数据结构,将一系列输入的数据划分为多个不同的部分,从而进行相应的后续处理。 自己在学习并查集之前也实现过这种类型,不过没有进行压缩,时间复杂度很大。 对于并查集的讲解,试着自己给自己讲一遍,觉得自己的理解还是挺清楚的,但要写博文的话实在太费时间了,暂时放弃。 推荐大家看并查集讲解,作者的代码写的非常清楚,讲解也很有趣。 传送门:http://acm.hdu.e原创 2014-12-21 09:21:44 · 565 阅读 · 0 评论 -
hdu_1879_继续畅通工程_kruscal_prim_再续
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1879 具体代码参见:http://blog.csdn.net/allianzcortex/article/details/42192829,之前在博客中的畅通工程第一序列。 问题分析: 在原来问题的基础上增加了一个标示位,如果flag=1的话说明已经修建过,flag=0的话说明还未被修建,要求最短路原创 2014-12-28 15:18:31 · 461 阅读 · 0 评论 -
hdu_1233_畅通工程再续_最小生成树_kruscal_prim
本来差点都要放入”存疑“归档了,午休之后回来仔细检查一下代码,发现测试用例”1 1 2 6“通不过,结果是因为自己在遍历边时用的是 for(i=0;i 每个人写代码一段时间后都会有固定的规范,比如这道题用并查集+kruscal就看到多种写法,有的人是多不喜欢main()里面的函数啊。 Kuruscal代码如下: #include #include #include using namesp原创 2014-12-27 14:31:53 · 497 阅读 · 0 评论 -
hdu_1874_畅通工程_最短路_dijkstra
!!! 先附上一开始写的代码,测试用例没有问题,但你发现为什么它一直通不过了吗? #include #include #include using namespace std; const int maxn=1000; const int INF=999999; int n,m; int map[maxn][maxn]; int dist[maxn]; void dijkstra(int s原创 2014-12-29 20:37:06 · 310 阅读 · 0 评论 -
hdu_2544_路口最短距离_最短路_dijkstra
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2544 解题思路:题意已经非常明显了,这道题用来检测自己对最短路的理解和代码的熟悉程度,早起热身,一次AC。现在看来属于很水的题。 代码如下:#include #include #include using namespace std; const int maxn=1000; const int I原创 2014-12-30 09:07:11 · 437 阅读 · 0 评论 -
hdu_1285_拓扑排序_
开始的代码: #include #include #include #include using namespace std; const int maxn=1000; //算法的思想自己已经了解了,那么先按照最基本的it来实现 int map[maxn][maxn];int in[maxn];int visit[maxn];//定义入度 int main(void) { int n,m原创 2014-12-30 11:17:28 · 444 阅读 · 0 评论 -
hdu_1048_字符串_水
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1048 是在是不能再水的一道题,适合热身练习用。注意它每次都是读取一行,用c语言的gets也可以。 顺便放一下常用的asc码: 0—9: 48—57 A—Z: 65—90 a—z: 97—122 代码如下: #include #include #include #include原创 2015-01-01 11:10:42 · 452 阅读 · 0 评论 -
hdu_1878_欧拉回路_并查集
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1878 对于无向图来说,判断是否存在欧拉回路,即是否存在一个回路,每个边只走一次就可以遍历所有的边,且不重复。 充要条件为: ①不存在度数为奇树的点 ②存在一条联通路径 对于第一点:我们在每输入一条边的时候,都将对应的两点度数++,最后进行判断。 对于第二点:用并查集来解决,因为如果存在一条路径的原创 2015-01-01 09:40:27 · 315 阅读 · 0 评论 -
hdu_1251_统计难题_字典树
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1251 做到这道题的时候突然想起某乎上的一个问题:如何评价360面试官对trie树的评价? 只能说想象一下一个汉字后面可能接的数目,即使以10个数字作为基准,那花费的空间也是不敢想象的。 代码如下: #include #include #include #include using namespa原创 2015-01-01 16:18:18 · 444 阅读 · 0 评论 -
hduing1501_判断合并_dfs_数组
#include #include #include #include using namespace std; const int maxn=1000; char s1[300],s2[300],s3[600]; //数组的长度 int len1,len2,len3; int visit[maxn][maxn]; int dfs(int i,int j,int k) { if(visi原创 2015-01-02 10:52:27 · 435 阅读 · 0 评论 -
hdu_2072_统计单词数_set_检测字符串
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2072 思路:每输入一行单词,检验有多少个不同的单词 关键在于两点:①单词不要重复 ②注意好空格 自己用作为集合,已经去掉了第一点;再用sstream(参见http://blog.csdn.net/allianzcortex/article/details/42168259,个人博客之前的说明)去掉原创 2014-12-28 19:00:19 · 542 阅读 · 0 评论 -
hdu_1257_贪心_模拟_最小拦截系统
气cry~,思路完全正确,但因为实现时的一系列小问题,花了将近半个小时才A掉。 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1257 思路:每当有导弹来临时: ①如果没有任何当前的系统可以达到导弹的高度,则在拦截数组里新增一个,并且最大打击高度为导弹高度。 ②如果有能达到导弹高度,则找到最接近导弹的这一点(可以使浪费的高度最小),并将导弹高原创 2014-12-27 09:02:28 · 459 阅读 · 0 评论 -
hdu_1049_水_模拟
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1049 和贪心没有任何关系,很简单的模拟题: #include #include #include using namespace std; const int maxn=1000; int main(void) { int n,d,u; int i,j,k; while(c原创 2014-12-26 21:04:11 · 336 阅读 · 0 评论 -
hdu1008_Elevator_水题
Problem DescriptionThe highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified or原创 2014-12-01 18:37:49 · 550 阅读 · 0 评论 -
hdu_1175_BFS+剪枝_用转弯次数来限定
先贴代码,明天再补上说明 #include #include #include #include #include using namespace std; const int maxn=1000; int map[maxn][maxn],visit[maxn][maxn]; int dir[4][2]={1,0,-1,0,0,1,0,-1}; int n,m; int sx,sy,ex,ey;原创 2014-12-15 20:18:17 · 394 阅读 · 0 评论 -
hdu_2260_项链问题_DFS_回溯法
这道题开始是想用贪心或者DP求解的,但看它分类在搜索这块,所以就想用DFS。 一开始一直提示TLE,最后搜了一下别人的解题报告,发现思路很相似,不同之处在于他没有考虑重复的路径。 比如说 1 2 3 4 ,当以1为开端时,会把所有有12,13,14的都穷举到,那么到2时,就不用考虑1了,考虑23,24就可以。 代码写的也很有巧妙性,注意在每次DFS时会标记已经使用,所以搜索后要置0。 #i原创 2014-12-20 11:40:36 · 758 阅读 · 1 评论 -
hdu_1072_nightmare_BFS_用时间来限定
代码来自于别人,自己写怎么都AC不过,明早一早要看的内容: //HDU1072 Nightmare //http://acm.hdu.edu.cn/showproblem.php?pid=1072 //这道题和别的bfs不一样的是它有一个还原点的设置,所以在标记用过的点时 //不能单单以坐标为标准,还要有这一点的时间 #include #include using namespace std;原创 2014-12-19 21:50:11 · 325 阅读 · 0 评论 -
hdu_1313_黑红格子问题_DFS_BFS_水
很基础的一道题,和油田问题有很多相似之处。 思路见代码 1.DFS深度搜索: #include #include #include #include using namespace std; const int maxn=1000; char map[maxn][maxn]; int vis[maxn][maxn]; int sx,sy; int n,m; void dfs(int x,i原创 2014-12-19 15:04:23 · 755 阅读 · 0 评论 -
hdu_2577_键盘打字_模拟_DP
呃,hdu不支持string类型字符串,在用string s 里的strlen(s.c_str())时直接显示无法编译通过:-D。 首先自己想的是用模拟法去做: #include #include using namespace std; //首先是不用DP的解法,判断依据应该是连续两个是否连续 int main(void) { int n,m,T; int i,j,k;原创 2014-12-05 17:11:44 · 465 阅读 · 0 评论 -
hdu_1087_jump_DP
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1087 分析: 这是很典型的可以用DP求解的问题,且具有明显的非贪心选择性质。 输入一组数字,只能由小数跳到大数。问最终能取得的路径上数字和是多少。 特例就是:4 3 3 2 1,结果为3。 定义状态方程:sum[i]表示从前往后在第i个棋子上所能取得的最大路径和。 则一开始sum[i]=原创 2014-12-06 09:09:54 · 413 阅读 · 0 评论 -
hdoj-1058 hunble numbers DP解法
自己做这道题的时候心浮气躁,一直没有把握好prime这里的意思。当然从理论上讲,*4会比*5得到的数更好(因为4并不是素数),但如果 仔细看的话就会发现实际上偶数是可以在前几个数列里就能求出的。 最后照着别人的思想自己写了一下代码,AC,但一点也不开心。 呃,这道题按照分类是在DP里面,但没有明显的表达式。#include #include #include #include using n原创 2014-11-30 15:47:41 · 577 阅读 · 0 评论 -
hdu1022-火车-栈的使用
今天做的水题有点多,犹豫要不要发出来,不管了,明天再说…… 想起大二下的时候数据结构为了一个栈的写费了多长的时间,现在用STL的格式简洁明快。所以说:不要重复造轮子。 简直要哭了。 随便写写吧:完整代码如下,一些小的感受也保存了起来,明天再好好练习:#include #include #include #include using namespace std; //1、2、3表示的只是入栈的原创 2014-11-30 21:47:39 · 374 阅读 · 0 评论 -
hdu_1009_贪心_换取食品问题
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1009 这道题思路是很简洁的,按照取值从大到小排序,之后依次进行加减。 一开始写的时候习惯性思维按“return weight 自己在上算法课写贪心策略求解的时候,用的是两个for循环下的冒泡排序,现在看来真是:naive~ 代码如下:#include #include #include #inc原创 2014-12-26 16:38:11 · 680 阅读 · 0 评论 -
hduoj-2084 数字塔问题 DP
还是按照之前的步骤,大概写,再精化。 典型的不能再典型的DP问题,最优子结构和重叠子问题性质都满足的很好。 使用DP求解,一开始在定义最大值的时候将1000写成000,导致了一系列完全不能理解的问题。 #include #include using namespace std; #define maxnum 1000 int num[maxnum][maxnum]; int d[maxnum原创 2014-11-30 10:03:13 · 697 阅读 · 0 评论