poj
文章平均质量分 78
RIPwangh
山东理工大学本科学生
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
POJ-2488-A Knight's Journey-DFS
题意: 给你一个, q*p 的棋盘,让你用马的走法,把所有点都走一遍,如果不行的话,输出impossible, 可以的话,按字典序小的路径的输出 #include #include #include int flag[27][27]; int dx[]={-1,1,-2,2,-2,2,-1,1}; int dy[]={-2,-2,-1,-1,1,1,2,2}; int p, q,num; st原创 2015-08-18 11:06:10 · 515 阅读 · 0 评论 -
poj-1789--Truck History-最小生成数
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原创 2015-07-30 19:57:07 · 643 阅读 · 0 评论 -
poj -2513-Colored Sticks-哈希&并查集或者字典树&并查集
题意: 给你任意条木棍,读到文件结束输入结束,木棍两边有颜色,相同颜色的可以连到一起,问是否可以连成一个欧拉路,这道题看着有两种做法 1. 哈希&并查集 做法是字符串哈希,去判断奇数度的个数,个数大于等于3的话是代表不能形成一个欧拉路的,小于3的话,就看一下并查集,看是否这几个点是一个图上的, 2. 字典树&并查集 做法略显麻烦,原因在于建字典树吧,其他的与上遍的做法相似原创 2015-08-12 14:32:01 · 576 阅读 · 0 评论 -
poj-3080-Blue Jeans-串-暴力
The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was populated.原创 2015-08-07 16:10:02 · 631 阅读 · 0 评论 -
poj-3020-Antenna Placement-二分图
Description The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden. The most striking reason why they got the job, is their disco转载 2015-08-07 10:09:40 · 881 阅读 · 0 评论 -
poj-3026-Borg Maze-最小生成树
Description 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 ci原创 2015-07-31 14:07:57 · 1063 阅读 · 0 评论 -
poj-1328 Radar Installation--枚举
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the原创 2015-07-28 15:37:39 · 563 阅读 · 0 评论 -
POJ-2418-Hardwood Species-字典树
统计各个单词占得比例 #include #include #include #include #include using namespace std; int top, t=0; struct node { int next[130]; int n; }pos[3500]; struct nod { char s[35]; int num; }ls[120原创 2015-08-13 20:12:46 · 461 阅读 · 0 评论 -
*poj-3083-Children of the Candy Corn-图的BFS DFS
The cornfield maze is a popular Halloween treat. Visitors are shown the entrance and must wander through the maze facing zombies, chainsaw-wielding psychopaths, hippies, and other terrors on their que原创 2015-07-31 16:04:24 · 560 阅读 · 0 评论 -
poj3295 -- Tautology--构造法
Description WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some subset of the possible symbols K, A, N, C, E, p, q, r, s, t. A Well-formed formula (WFF) is any s原创 2015-07-29 09:53:49 · 696 阅读 · 0 评论 -
poj-3253-sdutoj-2127-哈夫曼树-优先队列
Description Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer le原创 2015-08-11 18:39:57 · 625 阅读 · 0 评论 -
poj-1094-Sorting It All Out-拓扑排序
Description An ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from smallest to largest. For example, the sorted sequence原创 2015-08-06 16:41:12 · 503 阅读 · 0 评论 -
poj-Eqs-哈希
题意: 给你 a1, a2, a3, a4, a5,的值让你去求几个不同的解,解的范围在-50到50,解不等于0; 思路: 技巧枚举暴力 把方程变一下: 去枚举x1,x2,哈希,然后取枚举x3.x4,x5; 有负数的,需要加上25000000,然后存起来 但是这样的话,仍会MLE,需要把int 变成 short , 这个占2个字节,不会MLE #include #inc原创 2015-08-17 10:43:54 · 847 阅读 · 0 评论 -
poj- 2002-Squares-哈希|除法散列法
题意: 给你n 个点的坐标,让你去算一下,能够形成多少个正方形 思路: 1.枚举两个点,然后推出那两个的坐标,这样会有重复的,最后需要除以4 已知: (x1,y1) (x2,y2) 则: x3=x1+(y1-y2) y3= y1-(x1-x2) x4=x2+(y1-y2) y4= y2-(x1-x2) 或 x3=x1-(y1-y2) y3= y1+(x1-x2原创 2015-08-17 15:14:16 · 804 阅读 · 0 评论 -
poj-2503-Babelfish-字典树orMAP or 字符串哈希
题意: 给你一组字符串, 每一行有两个串,a,b; 输入空行结束 给你一个串c,问你在前面的第二列的数组中出没出现过,有的话,输出前面的那个,没有的话输出eh sscanf函数应用是,把一个串,分割成不同类型的 1. map 2625ms #include #include #include #include #include #include #include原创 2015-08-17 21:26:22 · 807 阅读 · 0 评论 -
poj-2442-Sequence-优先队列||堆
题意: 输入m个数集,每个含n个数,求从每个集合取一个数后,按非降序输出前n小的和; 思路: 1.优先队列 2.堆 1.优先队列#include #include #include #include #include #include using namespace std; int main() { int t; scanf("%d",&t); whil原创 2015-08-18 10:01:25 · 537 阅读 · 0 评论 -
poj-1860-Currency Exchange-Bellman
Description 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 currenci原创 2015-08-03 19:31:56 · 497 阅读 · 0 评论 -
POJ-3009-Curling 2.0- DFS
#include #include #include int dx[]={0,0,1,-1}; int dy[]={1,-1,0,0}; int n, m, step; int qx, qy, zx, zy; int mp[27][27]; int mans=9999999; void dfs(int x, int y) { int i,xx,yy; if(step >= 10 |原创 2015-08-18 14:53:20 · 479 阅读 · 0 评论 -
poj-2251-Dungeon Master-BFS
题意: 从S到E,一个三维的BFS可以解决,多一维,可以这样去理解,二维相当于一个平面,而三维的相当于一栋楼房,只是在z上多了几个平面而已 另外,第一次用队列写BFS好开心,以前都是模拟队列,也是醉了 16ms #include #include #include #include #include #include using namespace std; int dx[]= {原创 2015-08-18 16:53:20 · 511 阅读 · 0 评论 -
poj - 1426-Find The Multiple-BFS
题意: 给你一个数n,让你找到一个由0,1构成的n的倍数 思路: 姿势对了,就过了 1.0#include #include #include #include #include #include using namespace std; long long bfs(int n) { queuep; while(!p.empty()) { p.pop原创 2015-08-18 19:47:08 · 686 阅读 · 0 评论 -
POJ -3414-Pots
题意: 给你,两个容量分别为a,b的杯子,让你看需要几步可以得到c的水,不能的话,impossible,可以的话,输出步数,和路径 思路: BFS,暴搜 #include #include #include #include #include #include using namespace std; int a, b, c; struct node { int step;原创 2015-08-19 14:34:37 · 519 阅读 · 0 评论 -
poj-3087-Shuffle'm Up-模拟
题意: 实力转载 题目大意: 已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s1,最顶的c块牌归为s2,依此循环下去。 现在输入s1和s2的初始状态 以及 预想的最终状态s12 问s1 s2经过多少次洗牌之后,最终能达到状态s12,若永远不可能相同,则输出"-1"。 解题思路: 很浅白的模拟原创 2015-08-19 10:23:33 · 663 阅读 · 0 评论 -
poj-3126-Prime Path-BFS
题意: 给你两个素数,n,m; 问你能够最少几步把n变成m; 变的规则: 每次能够变一位数字,要求变完,仍然是素数; n,m都是4位数 思路: BFS,先用素数筛把10000都筛出来,然后用BFS,对个十百千位的数字去枚举(千位不能是0) 16ms #include #include #include #include #include #include using原创 2015-08-19 09:20:32 · 552 阅读 · 0 评论 -
POJ -2531-Network Saboteur-DFS
题意: 求两个子图的最大的割边的和 思路: DFS&枚举 把图上的点先全部分给0集合。然后取枚举哪几个是1集合的,去求最大的割边的和 CODE 47ms #include #include #include #include #include #include using namespace std; int mp[35][35]; int vis[35]; int n,ans;原创 2015-08-19 16:08:20 · 536 阅读 · 0 评论 -
POj-1129-Channel Allocation-DFS暴搜
题意: 实力转载题意 题目翻译: http://user.qzone.qq.com/289065406/blog/1303954302 当一个广播电台在一个非常大的地区,广播站会用中继器来转播信号以使得每一个接收器都能接收到一个强烈的信号。然而,每个中继器必须慎重选择使用,使相邻的中继器不互相干扰。如果相邻的中继器使用不同的频道,那么就不会相互干扰。 由于无线电频道是一有限的,一个给定原创 2015-08-20 16:08:43 · 1067 阅读 · 0 评论 -
poj -1416-Shredding Company-DFS
题目翻译: 公司现在要发明一种新的碎纸机,要求新的碎纸机能够把纸条上的数字切成最接近而不超过target值。比如,target的值是50,而纸条上的数字是12346,应该把数字切成四部分,分别是1、2、34、6。因为这样所得到的和43 (= 1 + 2 + 34 + 6) 是所有可能中最接近而不超过50的。(比如1, 23, 4, 和6 就不可以,因为它们的和不如43接近50,而12, 34,原创 2015-08-20 10:01:05 · 636 阅读 · 0 评论 -
POJ-1442-Black Box-优先队列
题意:给定M个数,每次可以插入序列一个数;再给N个数,表示在插入第几个数时输出一个数,第一次输出序列中最小的,第二次输出序列中第二小的……以此类推,直到输出N个数。 分析:因为输出时是按照先输出最小的,再输出第二小这样的方式输出的,相当于依次输出一个有序序列中的值。但因为这个序列不是固定不变的,而是不断的在更新,所以用数组是无法实现的。我们可以用优先队列来做。 定义两个优先队列,一个用原创 2015-08-20 19:40:49 · 652 阅读 · 0 评论 -
POJ - 1905-Expanding Rods-数论-二分&几何
题目意思: 一根两端固定在两面墙上的杆 受热弯曲后变弯曲 求前后两个状态的杆的中点位置的距离 解题思路: 几何和二分的混合体 图,蓝色为杆弯曲前,长度为L 红色为杆弯曲后,长度为s h是所求 依题意知 S=(1+n*C)*L 又从图中得到三条关系式; (1) 角度→弧度公式 θr = 1/2*s (2) 三角函数公式转载 2015-09-10 21:20:57 · 661 阅读 · 0 评论 -
POJ-2676-Sudoku-DFS
题意:每行每列每个九空格数字不同,输出一种符合题意即可 思路: DFS&暴力 #include #include #include int mp[10][10]; int mx[10][10]; int my[10][10]; int mk[10][10]; int cp; struct node///需要填的空 { int x; int y; }ls[85]; int dfs(in原创 2015-08-20 15:07:55 · 613 阅读 · 0 评论 -
POJ-1276-Cash Machine-多重背包
题目大意: 有各种不同面值的货币,每种面值的货币有不同的数量,请找出利用这些货币可以凑成的最接近且小于等于给定的数字cash的金额。 思路: 转化为01背包 转化为完全背包 1.01背包 #include #include #include using namespace std; int dp[110000], t[30000], s[2000][2]; int main()原创 2015-08-21 16:15:35 · 608 阅读 · 0 评论 -
POJ-1837-Balance -01背包
提示:动态规划,01背包 初看此题第一个冲动就是穷举。。。。不过再细想肯定行不通= =O(20^20)等着超时吧。。。 我也是看了前辈的意见才联想到01背包,用动态规划来解 题目大意: 有一个天平,天平左右两边各有若干个钩子,总共有C个钩子,有G个钩码,求将钩码全部挂到钩子上使天平平衡的方法的总数。 其中可以把天枰看做一个以x轴0点作为平衡点的横轴 输入: 2 4 //C 钩子转载 2015-08-21 10:55:35 · 548 阅读 · 0 评论 -
poj-2492 -A Bug's Life-并查集的使用
题目意思: 给出N条虫子,然后a和b交配,给出M对a和b后问有没有同性恋的虫子 思路: 并查集: 把相同性别的虫子连到一起,看是否有矛盾 CODE #include #include #include #include #include using namespace std; int ls[20010]; int f[20010]; int fid(int x) { r原创 2015-10-25 21:41:47 · 757 阅读 · 0 评论 -
poj-2996-2993-Help Me with the Game-模拟法
Description Your task is to read a picture of a chessboard position and print it in the chess notation. Input The input consists of an ASCII-art picture of a chessboard with chess pieces on positio原创 2015-08-03 09:40:31 · 476 阅读 · 0 评论 -
poj-1836-Alignment-动态规划
题意: 给你一排人的身高,要求每个人至少能够看到一边的排头(左边或右边),要删除的最小的人数 思路: 相信大家做过最长上升子序列的问题,而这个只需把它正着来一遍LIS,反着来一遍,然后枚举那个中间点 CODE #include #include #include double ls[1100]; int l[1100], lx[1100]; int main() { int原创 2015-08-24 14:56:09 · 548 阅读 · 0 评论 -
POJ-1260-Pearls-动规
题意:要买若干种价值的珍珠,但买某种珍珠必须多付10颗此种珍珠的价钱,及如果买价值为1的珍珠100颗,必须付的钱数为110。一颗珍珠可以用比它贵的珍珠充数,因此买多种珍珠的时候用贵的代替便宜的可能更省钱。例如买100颗价值为2的、1颗价值为1的,此时买101颗价值为2的为较优方案。输入要买的若干种珍珠,可用高价珍珠充数的条件下,问最少需要花费多少钱。 经典dp: 高档次的珍珠若要和低档次的珍珠原创 2015-08-24 17:29:45 · 624 阅读 · 0 评论 -
poj-3041-Asteroids -二分图的最大匹配
Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conveniently locate原创 2015-08-07 09:18:04 · 669 阅读 · 0 评论 -
POJ-3267-The Cow Lexicon-动规×
题意:给定字符串msg,再给定W个单词,要求从s中去掉最少的字符后能够被这些单词表示。求最少去掉多少字符。 用d[ i ]表示从msg[ 0...i ]中最少去掉字符的个数, remove [ j, k ] 表示msg[ j ... k ] 中包含了某个单词后去掉的字符个数。 状态转移方程就为 d[ i ] = min ( d[ j - 1] + remove[ j, i ] ),0 i。原创 2015-08-24 16:20:51 · 574 阅读 · 0 评论 -
poj-2299-Ultra-QuickSort-归并排序求逆序数--或树状数组
Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the seque原创 2015-08-10 15:24:04 · 829 阅读 · 0 评论 -
poj-1068 Parencodings--模拟法
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p1 p2...pn where pi is the number of left parentheses bef原创 2015-07-29 11:18:29 · 540 阅读 · 0 评论 -
POJ-1159-Palindrome-lcs扩展
题意: 看需要增加几个字母可以使该串变成回文串 思路: LCS的扩展,把串反过来,然后找他们的最长公共子序列的长度,用n减去这个数就可以了 方法1: LCS普通 CODE 49720K 688ms #include #include #include #include #include using namespace std; short c[5005][5005];原创 2015-08-25 11:19:06 · 458 阅读 · 0 评论
分享