poj 1950(搜索)】的更多相关文章

Dessert Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5430   Accepted: 2029 Description FJ has a new rule about the cows lining up for dinner. Not only must the N (3 <= N <= 15) cows line up for dinner in order, but they must place a…
catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个单位,3. 移动到当前位置的二倍处.输出移动的最少次数. 解题思路 使用搜索,准确地说是广搜,要记得到达的位置要进行标记,还有就是减枝. 详情见代码实现. 代码实现 #include<cstdio> #include<cstring> #include<iostream>…
目录 POJ 1426 POJ 1321 POJ 2718 POJ 3414 POJ 1416 POJ 2362 POJ 3126 POJ 3009 个人整了一些搜索的简单题目,大家可以clone来练习,vjudge链接直接公开了.以下部分代码省略了头文件,总之each就是for循环,rush()就是输入T个样例然后while(T--) vjudge练习地址:https://vjudge.net/contest/330414 POJ 1426 二进制的数实在太大了,所以用数组下标直接代表二进制数…
Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13923   Accepted: 5424 Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled…
题目链接:http://poj.org/problem?id=1011 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; ; int a[maxn]; int N; int sum; int len,cnt; bool used[maxn]; bool cmp(int a,int b){ return a > b;…
http://poj.org/problem?id=1190 题解:四个剪枝. #define _CRT_SECURE_NO_WARNINGS #include<cstring> #include<cctype> #include<cstdlib> #include<cmath> #include<cstdio> #include<string> #include<stack> #include<ctime>…
Network Saboteur Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Java class name: Main [Submit] [Status] [Discuss] Description A university network is composed of N computers. System administrators gathered informat…
思路: 抄的题解 这叫搜索? 难以理解 我觉得就是枚举+逼近 //By SiriusRen #include <cmath> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,recx,recy,x,y; int gcd(int a,int b){ return b?gcd(b,a%b):a; } int main(){ while(~sc…
poj2549 Sumsets 题目链接: http://poj.org/problem?id=2549 题意:给你一个含有n(n<=1000)个数的数列,问这个数列中是否存在四个不同的数a,b,c,d,使a+b+c=d;若存在则输出最大的d 思路:完全暴力的话O(n^4),会T,可以考虑双向搜索,公式变形为a+b=d-c:分别枚举a+b和c-d,将值和下标存在结构体中,再二分查找即可 #include<cstdio> #include<iostream> #include&…
/* 这个代码运行的时间长主要是因为每次枚举之后都要重新计算一下和的值! 如果要快的话,应该在dfs,也就是枚举的过程中计算出前边的数值(这种方法见第二个代码),直到最后,这样不必每一次枚举都要从头再算一遍值! */ 1 #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; ]; ]={'+', '-', '.'}; int…
描述: 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,000) on the same number line. Farmer John has t…
Channel Allocation Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u Java class name: Main [Submit] [Status] [Discuss] Description When a radio station is broadcasting over a very large area, repeaters are used to ret…
Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48605   Accepted: 18339 Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be fille…
Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12351   Accepted: 5982 Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in…
The Game Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6247   Accepted: 1601 Description A game of Renju is played on a 19*19 board by two players. One player uses black stones and the other uses white stones. The game begins in an emp…
直接DFS,因为实在没想到什么剪枝了... 注意一点是,10.11使用的是1011哦 #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #define LL __int64 using namespace std; int n,ct,k; char str[20]; void dfs(LL sum,LL last,int pos){ if(pos==n+1)…
思路: 暴力枚举好了..每回判断一下-- 用long long会超时 但是10^20会爆int... 不过仔细想一想 超过10^9的数肯定拼不回0啊-- 猥琐用int AC了 (当然可以打表 ) // by SiriusRen #include <cstdio> #include <iostream> #include <algorithm> using namespace std; int n,s[16],cnt=0,r[16]; void dfs(int t) {…
剪枝: 1.从后向前枚举 2.迭代加深 然后就0msAC了 //By SiriusRen #include <cstdio> using namespace std; int n,T,s[105]; bool dfs(int t){ if(s[t]==n)return 1; if(t>=T)return 0; for(int i=t;i>=1;i--){ s[t+1]=s[i]+s[t]; if(dfs(t+1))return 1; } } int main(){ s[1]=1;…
-->Dessert Descriptions: 给你一个数N(3<=N<=15);每个数之间有三种运算符“‘+’,‘-’,‘.’”.输出和值等于零的所有的运算情况及次数num,如果num大于20,则只输出前20中情况.运算符‘.’相当于连接符,例如:11.22 <-> 1122. Sample Input 7 Sample Output 1 + 2 - 3 + 4 - 5 - 6 + 7 1 + 2 - 3 - 4 + 5 + 6 - 7 1 - 2 + 3 + 4 - 5…
http://poj.org/problem?id=1011 这是一道POJ的搜索的题目,最开始确实难以理解,但做过一些搜索的题目后,也没那么难了. 大概题意就是,现在有N根木头,要拼成若干根木头,并且这些木头要相等的长度,并且每一根木头都要用上,求组成的木头最短长度是多少 思路: 首先木头肯定要由大到小进行排序,组成的最短的木头的长度的范围应该在最长的木头到所有的木头之和之间. 其次就是木头使用过后不能在使用,所以木头应该进行标记. #include <stdio.h> #include &…
BFS广搜题目有时间一个个做下来 2009-12-29 15:09 1574人阅读 评论(1) 收藏 举报 图形graphc优化存储游戏 有时间要去做做这些题目,所以从他人空间copy过来了,谢谢那位大虾啦. pku 1175 Starry Night 题目地址:http://acm.pku.edu.cn/JudgeOnline/problem?id=1175 解法:BFS,要注意的是如何判断图形是一样的,我的做法就是计算每两个点的距离之和. 看:http://hi.baidu.com/doxi…
Sudoku Problem's Link:   http://poj.org/problem?id=2676 Mean: 略 analyse: 记录所有空位置,判断当前空位置是否可以填某个数,然后直接DFS,注意从后往前搜索,时间比正向搜快很多.16ms水过 Time complexity: O(n) Source code:  // Memory Time // 1347K 0MS // by : crazyacking // 2015-04-10-14.30 #include<map>…
Sticks Problem's Link:   http://poj.org/problem?id=1011 Mean: http://poj.org/problem?id=1011&lang=zh-CN&change=true analyse: 爆搜,但是其中蕴含着很多剪枝. Time complexity: O(n^2) Source code:  // Memory Time // 1347K 0MS // by : Snarl_jsb // 2014-11-07-17.14 #i…
POJ 1129 Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14191   Accepted: 7229 Description When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receive…
滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 92384   Accepted: 34948 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道载一个区域中最长底滑坡.区域由一个二维数组给出.数组的每个数字代表点的高度.下面是一个例子 1 2 3 4 5 16 17…
Test for Job Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 8990   Accepted: 2004 Description Mr.Dog was fired by his company. In order to support his family, he must find a new job as soon as possible. Nowadays, It's hard to have a job…
好久没看背包题目了!!!生疏了!!!! 这题是背包题!!!不过对于这题,解决方法还是搜索省时!!! 题意:第一行给你一个N和VV,接下来N行,每行一个数,求得是任选N个数组合求和,求组合的和大于VV而且减去VV的最小的差!!! 囧!!! ¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥ #include<stdio.h> #include<string.h> #include<string.h>…
题目地址: http://poj.org/problem?id=1475 两重BFS就行了,第一重是搜索箱子,第二重搜索人能不能到达推箱子的地方. AC代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <vector> #inc…
题目链接POJ NO.2386 解题思路: 这个也是一个dfs 的应用,在书上的例子,因为书上的代码并不全,基本都是函数分块来写,通过这个题目也规范了代码,以后能用函数的就都用函数来实现吧.采用深度优先搜索,从任意的w开始,不断把邻接的部分用'.'代替,1次DFS后与初始这个w连接的所有w就全都被替换成'.',因此直到图中不再存在W为止,总共进行DFS的次数就是答案.8个方向对应8个状态转移,每个格子作为DFS的参数最多调用一次,因此时间复杂度为O(8nm)=O(nm). AC 代码: #inc…
棋盘问题 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44012   Accepted: 21375 Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C. Input 输入含有多组测试数据.每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了…