上一页 1 ··· 33 34 35 36 37 38 39 40 41 ··· 61 下一页
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1895思路:就是先两两合并,然后排序一下二分就可以了,最后要注意的地方就是二分找到解得时候,还要看一下相邻的数是否与解相等(因为可能有多个这样的数)Ps:郁闷死了,一开始用的是long long ,然后wa到死,结果改成int就过了,而且那个1000000007也没有用,orz... 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define MAXN 333 8 int num[6] 阅读全文
posted @ 2013-05-18 10:01 ihge2k 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1044思路:看网上大牛们的做法都是bfs+dfs,弱菜表示不会啊,然后觉得bfs也应该不会超时吧,就搞了一把,orz...890ms险过。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<queue> 5 using namespace std; 6 #define MAXN 52 7 struct Node{ 8 int x,y,time; 9 int va 阅读全文
posted @ 2013-05-17 16:09 ihge2k 阅读(327) 评论(1) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1973思路:简单bfs,先打个素数表,然后就是广搜搞一下就ok了。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<queue> 6 #include<string> 7 using namespace std; 8 #define MAXN 10100 9 struct Node{10 string 阅读全文
posted @ 2013-05-16 17:14 ihge2k 阅读(418) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1885思路:对于钥匙,才4把,直接状态压缩搞一下就好了,然后就是开个三位数组标记状态了,跟普通bfs没什么区别。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<queue> 6 using namespace std; 7 #define MAXN 110 8 struct Node{ 9 int x,y,st 阅读全文
posted @ 2013-05-15 22:35 ihge2k 阅读(558) 评论(0) 推荐(0) 编辑
摘要: 贴几道bfs题。题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2216思路:用一个四维的数组来保存状态,然后就是一般的bfs了,不过要注意的S,Z的初始位置要置为'.'(这个地方debug了好久,orz...).View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<queue> 6 using namespace std; 7 # 阅读全文
posted @ 2013-05-14 23:51 ihge2k 阅读(251) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1538题意:最短路问题,但是要求出最短路的条数,同时要求出所有可能的最短路选择中javabean最多的情况。思路:求到终点的最短路径用Dijkstra,其路径更新条件(如果到某个点有多个路径长度一样的最短路径,则选择豆子总数最多的)就是直接加个else if条件就搞定了,最后就是dfs搜一下最短路的条数了,这个我就记忆化了一下。然后我一开始使用spfa写的,wa了好多次,orz...改成dijkstra就过了。 1 #include<iostream> 阅读全文
posted @ 2013-05-14 21:53 ihge2k 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1067思路:学会了手写Hash。。。orz....纪念一下。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<queue> 6 using namespace std; 7 #define MAXN 1000007 8 typedef long long ll; 9 ll Hash[MAXN]; 10 11 st 阅读全文
posted @ 2013-05-14 16:44 ihge2k 阅读(708) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2438网上大牛思路:可以根据边界,汽车已经转弯,设水平方向为x轴,垂直方向为y轴。则汽车的内边界(靠近里面的边界)的直线方程式f(x)为:y=x*tan(a)+l*sin(a)+d/cos(a).其中a是汽车与x轴的夹角当y=X时,求解出的-x即为汽车的内边界到y轴的距离h,若h小于Y即可转弯,若大于Y就不能转弯。所以只需要利用方程式,求-x的最大值,即可判断能否通过。由于f(x)是凸函数(随着x的增大y先增大后减小),所以,需要借助三分求解。图示:第一道三分求极值题啊!!! 1 #include 阅读全文
posted @ 2013-05-14 12:30 ihge2k 阅读(1333) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160思路:就是排序后求最长递增子序列,只不过多了一个判断(s下降)以及最后输出下标,我们可以用一个pre[]数组来记录路径,最后递归输出就行了。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 #define MAXN 1010 7 struct Mice{ 8 int w,s,id; 阅读全文
posted @ 2013-05-13 21:55 ihge2k 阅读(398) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1252题意都读了半天,orz...给出n个结点,每两个结点之间都有一个线路想通,不过有不同的颜色,然后给三个piece,分别在三个初始位置,piece移动的条件是通过的路径的颜色必须要与另外两个piece所在位置之间的路径颜色想同,求使三个点移动到同一个位置上所需要的最小步数……开个三位数组记录一下状态就好了,简单bfs.View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 阅读全文
posted @ 2013-05-12 23:25 ihge2k 阅读(311) 评论(0) 推荐(0) 编辑
上一页 1 ··· 33 34 35 36 37 38 39 40 41 ··· 61 下一页