![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
ACM_搜索
文章平均质量分 75
奇怪的猪猪
whu,cuhk
展开
-
poj 3258 River Hopscotch 二分答案
题目地址: http://poj.org/problem?id=3258 题目思路: 首先,如果只减少一部,那么一定要干掉最短的那段距离(一旦不消灭,最小的还是它,并没有达到使最小值取最大的理想情况)。 但是如果有很多边取到最小,具体去除哪一个点就有点麻烦了。如果两个最小距离连着,去除公共点最好。 如果没有连着,四个点分别考虑紧邻的,取最小的。 如果多于两条线段取最小随便去,如果仅有一条取最小原创 2013-09-22 02:20:57 · 964 阅读 · 0 评论 -
LA6142 Radiation 二分查找
题目地址:LA6142原创 2014-04-04 01:20:59 · 485 阅读 · 0 评论 -
toj 1056 Labyrinth 搜索,树的直径
题目地址:toj1056 接上一篇 同样 还是求树的直径 直接两遍dfs 代码: #include #include #include #include using namespace std; #define INF 1000000000 typedef pair pii; map map; char p[1005][1005]; bool vis[1005][10原创 2014-03-22 22:39:10 · 860 阅读 · 0 评论 -
LA 6275 Joint Venture 二分查找,判重
题目地址:点这里原创 2014-05-01 23:44:53 · 623 阅读 · 0 评论 -
Regional_2011_H Holiday's Accommodation
题目地址: 1 LA 戳这里 2 hdu 2011_Chengdu_H 题目大意: 给你一颗树 ,告诉你每条边的权值,现在每个节点上的人要到其他的地方去,问所有里程加起来最多可以是多少? 先估计一下上界: 对于每一条边: 它作为割边将图分为两部分,假设这两边的人都尽可能的夸过这条边,这样在这条边上的贡献将达到最大。 先转化为有根树后,取2*min(k,n-k) k是原创 2014-03-08 20:42:12 · 567 阅读 · 0 评论 -
hdu 2553 N皇后问题 搜索 回溯法
题目地址: hdu 2553 直接小白书上面的回溯法 但是不知道有多少组数据 所以打一个表~ 代码: #include using namespace std; int C[10]; int n; int tot=0; int ans[10]; void dfs(int cur) { if(cur==n) tot++; else fo原创 2014-02-26 18:16:26 · 656 阅读 · 0 评论 -
zoj 1089 Lotto
题目地址:zoj 1089 题目:就是生成组合。 用dfs来写, 其中“相邻的边”实际上就是每次可以选择把某一位放入输出组中,也可以选择不放进去。 形成一“路径选择二叉树”。 搜到了一条路径就“return” 来回溯 cnt-- 就是把当前节点pass掉了~ 代码: #include #include using namespace std; int p[13]; //int原创 2014-02-26 03:24:52 · 553 阅读 · 0 评论 -
poj 3126 Prime Path bfs求最短路
题目地址: poj 3126 题目大意: 每次只允许变动一位 求最少变动多少次可以把一个四位素数变为另一个四位素数。 还是直接bfs求最短路,每个素数是一个节点,判断是否相邻用枚举的方法,分别枚举个十百千位。 记得layer[next] = layer[cur]+1; 所以取出每一位的时候要用cur的副本 代码: #include #include #include #includ原创 2014-02-25 00:55:11 · 574 阅读 · 0 评论 -
2013杭电warm up1 1002 Pet 求树结点的高度(bfs,dfs两种求法)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4707 题目给出一颗树,要求求出深度大于D的结点的个数。 有两种方法,改写dfs,给一个参数放层数(额,其实这里不需要转化为有根树,多于了) 代码: #include #include #include #include using namespace std; #define maxn原创 2013-09-18 00:17:14 · 1006 阅读 · 0 评论 -
poj 3278 Catch That Cow bfs求最短路径
最近练习一组搜索题 题目地址:poj 3278 题目大意: 给你一个数n 你可以+1,-1,*2,怎么用最少的步骤数达到给定的k,如果没有这样的方案输出-1; 用图论的理论搜索出一条路径即可 先看代码: #include #include #include #include using namespace std; #define max 100005 int c原创 2014-02-24 15:17:11 · 682 阅读 · 0 评论 -
poj 1562 ,hdu 1241 Oil Deposits dfs,bfs 求连通分支数
题目地址: http://poj.org/problem?id=1562 http://acm.hdu.edu.cn/showproblem.php?pid=1241 直接遍历求连通分支数, dfs方法: #include #include #include using namespace std; int map[105][105]; int vis[1原创 2013-09-26 00:35:18 · 815 阅读 · 0 评论 -
poj 3984 迷宫问题 dfs 求迷宫路径
题目地址:http://poj.org/problem?id=3984 利用图论中深搜的思想,存在边就是x,y -> x+1,y 还有x,y -> x,y+1 然后仍然是访问未访问的而且不是墙壁的地方。 这样保证不走已经搜索过,走不通的路。 唯一一种需要重复访问已经访问的结点的情况是已经无路可走了,只能返回,这样就在栈中将路径取出来,把自己现在的那个先pop掉,然后实现回溯。 最后原创 2013-09-25 18:03:48 · 3905 阅读 · 0 评论 -
zoj 3366 Light Bulb 三分
题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3366 思路: 题目就是要求函数 (h*D-H*x)/(D-x)+x 的最大值,其中 x>=0 x 一开始直接求导,令导数为0 得到wa的程序: #include #include using namespace std; int main() {原创 2013-09-24 23:43:18 · 971 阅读 · 0 评论 -
poj 3122 Pie 二分答案
题目地址: http://poj.org/problem?id=3122 还是找到了单调函数--分给m人对最大尺寸f(m) 是m的不增函数,那么具体给定m是,二分f(m)使用>=f+1 l=mid 而不是>来保证尽可能取得大 细节: 应该直接二分答案,而不是算出比较精确的半径平方,最后*PI输出,会产生误差,然后PI用arccos(-1),否则也会wa 代码: #include原创 2013-09-25 02:19:28 · 981 阅读 · 0 评论 -
poj 1905 Expanding Rods 二分答案
题目地址: http://poj.org/problem?id=1905 思路: 列出方程 2*R*x=L‘ 2*R*sin(x)=L 两式相除即得 x/sin(x) = 1+n*c 前提x!=0 就是 n*c>0 答案就是 L/2* (1/sin(x)-1/tan(原创 2013-09-25 15:15:58 · 748 阅读 · 0 评论 -
codeforces#154_div2_B (253B) Physics Practical
题目地址:戳这里 思路:先排序 然后对每一个当前的p[i],用logn的方法 对每一个找到2*p[i] 的 upper_bound 用贪心的思想知道,肯定是去头去尾,不会去中间的。 算法复杂度: nlogn 注意一定是文件输入输出 代码: #include #include #include #include using namespace std; in原创 2014-03-26 01:31:38 · 572 阅读 · 0 评论