![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
poj
文章平均质量分 80
RIPwangh
山东理工大学本科学生
展开
-
poj-2492 -A Bug's Life-并查集的使用
题目意思: 给出N条虫子,然后a和b交配,给出M对a和b后问有没有同性恋的虫子思路:并查集: 把相同性别的虫子连到一起,看是否有矛盾CODE#include#include#include#include#includeusing namespace std;int ls[20010];int f[20010];int fid(int x){ r原创 2015-10-25 21:41:47 · 684 阅读 · 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 · 720 阅读 · 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 · 654 阅读 · 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 · 726 阅读 · 0 评论 -
poj-1094-Sorting It All Out-拓扑排序
DescriptionAn 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 · 445 阅读 · 0 评论 -
poj-3253-sdutoj-2127-哈夫曼树-优先队列
DescriptionFarmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needsN (1 ≤ N ≤ 20,000) planks of wood, each having some integer le原创 2015-08-11 18:39:57 · 546 阅读 · 0 评论 -
poj3295 -- Tautology--构造法
DescriptionWFF '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 · 616 阅读 · 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 · 478 阅读 · 0 评论 -
POJ-2418-Hardwood Species-字典树
统计各个单词占得比例#include#include#include#include#includeusing 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 · 383 阅读 · 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 · 444 阅读 · 0 评论 -
poj-3026-Borg Maze-最小生成树
DescriptionThe 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 · 978 阅读 · 0 评论 -
poj-3020-Antenna Placement-二分图
DescriptionThe 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 · 757 阅读 · 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 · 546 阅读 · 0 评论 -
poj -2513-Colored Sticks-哈希&并查集或者字典树&并查集
题意:给你任意条木棍,读到文件结束输入结束,木棍两边有颜色,相同颜色的可以连到一起,问是否可以连成一个欧拉路,这道题看着有两种做法1. 哈希&并查集 做法是字符串哈希,去判断奇数度的个数,个数大于等于3的话是代表不能形成一个欧拉路的,小于3的话,就看一下并查集,看是否这几个点是一个图上的,2. 字典树&并查集 做法略显麻烦,原因在于建字典树吧,其他的与上遍的做法相似原创 2015-08-12 14:32:01 · 497 阅读 · 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 · 548 阅读 · 0 评论 -
poj-2442-Sequence-优先队列||堆
题意: 输入m个数集,每个含n个数,求从每个集合取一个数后,按非降序输出前n小的和;思路:1.优先队列2.堆1.优先队列#include#include#include#include#include#includeusing namespace std;int main(){ int t; scanf("%d",&t); whil原创 2015-08-18 10:01:25 · 467 阅读 · 0 评论 -
POJ-2488-A Knight's Journey-DFS
题意:给你一个, q*p 的棋盘,让你用马的走法,把所有点都走一遍,如果不行的话,输出impossible, 可以的话,按字典序小的路径的输出#include#include#includeint 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 · 444 阅读 · 0 评论 -
POJ-1837-Balance -01背包
提示:动态规划,01背包初看此题第一个冲动就是穷举。。。。不过再细想肯定行不通= =O(20^20)等着超时吧。。。我也是看了前辈的意见才联想到01背包,用动态规划来解 题目大意:有一个天平,天平左右两边各有若干个钩子,总共有C个钩子,有G个钩码,求将钩码全部挂到钩子上使天平平衡的方法的总数。其中可以把天枰看做一个以x轴0点作为平衡点的横轴输入:2 4 //C 钩子转载 2015-08-21 10:55:35 · 478 阅读 · 0 评论 -
POJ-1276-Cash Machine-多重背包
题目大意:有各种不同面值的货币,每种面值的货币有不同的数量,请找出利用这些货币可以凑成的最接近且小于等于给定的数字cash的金额。 思路:转化为01背包转化为完全背包1.01背包#include#include#includeusing namespace std;int dp[110000], t[30000], s[2000][2];int main()原创 2015-08-21 16:15:35 · 464 阅读 · 0 评论 -
POJ-2676-Sudoku-DFS
题意:每行每列每个九空格数字不同,输出一种符合题意即可思路:DFS&暴力#include#include#includeint 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 · 513 阅读 · 0 评论 -
POJ - 1905-Expanding Rods-数论-二分&几何
题目意思: 一根两端固定在两面墙上的杆 受热弯曲后变弯曲求前后两个状态的杆的中点位置的距离解题思路:几何和二分的混合体图,蓝色为杆弯曲前,长度为L红色为杆弯曲后,长度为sh是所求依题意知S=(1+n*C)*L 又从图中得到三条关系式;(1) 角度→弧度公式 θr = 1/2*s(2) 三角函数公式转载 2015-09-10 21:20:57 · 566 阅读 · 0 评论 -
POJ-1442-Black Box-优先队列
题意:给定M个数,每次可以插入序列一个数;再给N个数,表示在插入第几个数时输出一个数,第一次输出序列中最小的,第二次输出序列中第二小的……以此类推,直到输出N个数。分析:因为输出时是按照先输出最小的,再输出第二小这样的方式输出的,相当于依次输出一个有序序列中的值。但因为这个序列不是固定不变的,而是不断的在更新,所以用数组是无法实现的。我们可以用优先队列来做。定义两个优先队列,一个用原创 2015-08-20 19:40:49 · 558 阅读 · 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 · 557 阅读 · 0 评论 -
POj-1129-Channel Allocation-DFS暴搜
题意:实力转载题意题目翻译: http://user.qzone.qq.com/289065406/blog/1303954302当一个广播电台在一个非常大的地区,广播站会用中继器来转播信号以使得每一个接收器都能接收到一个强烈的信号。然而,每个中继器必须慎重选择使用,使相邻的中继器不互相干扰。如果相邻的中继器使用不同的频道,那么就不会相互干扰。由于无线电频道是一有限的,一个给定原创 2015-08-20 16:08:43 · 958 阅读 · 0 评论 -
POJ -2531-Network Saboteur-DFS
题意:求两个子图的最大的割边的和思路:DFS&枚举把图上的点先全部分给0集合。然后取枚举哪几个是1集合的,去求最大的割边的和CODE 47ms#include#include#include#include#include#includeusing namespace std;int mp[35][35];int vis[35];int n,ans;原创 2015-08-19 16:08:20 · 464 阅读 · 0 评论 -
poj-3126-Prime Path-BFS
题意: 给你两个素数,n,m; 问你能够最少几步把n变成m; 变的规则: 每次能够变一位数字,要求变完,仍然是素数; n,m都是4位数思路: BFS,先用素数筛把10000都筛出来,然后用BFS,对个十百千位的数字去枚举(千位不能是0)16ms#include#include#include#include#include#includeusing原创 2015-08-19 09:20:32 · 480 阅读 · 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 · 580 阅读 · 0 评论 -
POJ -3414-Pots
题意:给你,两个容量分别为a,b的杯子,让你看需要几步可以得到c的水,不能的话,impossible,可以的话,输出步数,和路径思路:BFS,暴搜#include#include#include#include#include#includeusing namespace std;int a, b, c;struct node{ int step;原创 2015-08-19 14:34:37 · 428 阅读 · 0 评论 -
poj - 1426-Find The Multiple-BFS
题意:给你一个数n,让你找到一个由0,1构成的n的倍数思路:姿势对了,就过了1.0#include#include#include#include#include#includeusing namespace std;long long bfs(int n){ queuep; while(!p.empty()) { p.pop原创 2015-08-18 19:47:08 · 609 阅读 · 0 评论 -
poj-2251-Dungeon Master-BFS
题意:从S到E,一个三维的BFS可以解决,多一维,可以这样去理解,二维相当于一个平面,而三维的相当于一栋楼房,只是在z上多了几个平面而已另外,第一次用队列写BFS好开心,以前都是模拟队列,也是醉了16ms#include#include#include#include#include#includeusing namespace std;int dx[]= {原创 2015-08-18 16:53:20 · 442 阅读 · 0 评论 -
POJ-3009-Curling 2.0- DFS
#include#include#includeint 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 · 411 阅读 · 0 评论 -
poj-1860-Currency Exchange-Bellman
DescriptionSeveral 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 · 421 阅读 · 0 评论 -
poj-1125-Stockbroker Grapevine-Floyd
Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock m原创 2015-08-04 21:18:11 · 670 阅读 · 0 评论 -
poj-3349-Snowflake Snow Snowflakes-哈希
题意: 给你一个数n,然后给你n组数据,让你去找看是否有相同的雪花,很多人是把数据sort一遍,然后哈希,这样做能水过去,但是和题意有点差别,例如 1 2 3 4 5 6 和1 3 2 4 5 6,它不是相同的雪花,因为1的旁边的值不同啊, 这个题给了4000ms,看来很容易超时,一开始的思路是,建个结构体,下标是对应的那6个数的和对10011取于的结果,然后里面建一个二维数组,来存以原创 2015-08-12 09:18:01 · 493 阅读 · 0 评论 -
POJ-Round Numbers-组合数学
题意; 给你两个数n,m,让你看里面有多少个round数,(包括m,不包括n) round 数是对应的二进制数中0比1的个数多思路: 1.0 杨辉三角 2.0 分阶层去算(不同的数位)1,10,100,1000,这样是4个阶层,先算出p(二进制的数的长度)的所有的,然后再算和p相同长度,但是比该数小的round数CODE#include#in原创 2015-08-25 18:35:08 · 506 阅读 · 0 评论 -
POJ-1850-Code-组合数学
题意: 输出某个str字符串在字典中的位置,由于字典是从a=1开始的,因此str的位置值就是 在str前面所有字符串的个数 +1规定输入的字符串必须是升序排列。不降序列是非法字符串不要求用循环输入去输入若干组字符串,但若输入非法字符串则输出0,且结束程序,这是和POJ1496最猥琐的区别,很多同学只注意到规定str的长度不同,以为把str数组长度改一下直接复制就能AC再多刷一题了,殊原创 2015-08-25 20:08:30 · 477 阅读 · 0 评论 -
poj-2485-Highways-最小生成树
The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're pla原创 2015-07-30 20:12:58 · 455 阅读 · 0 评论 -
POJ-1942-Paths on a Grid-组合数学
给定一个矩形网格的长m和高n,其中m和n都是unsigned int32类型,一格代表一个单位,就是一步,求从左下角到右上角有多少种走法,每步只能向上或者向右走 解题思路:非常水的中学数学题,用组合做先简单建立一个数学模型:只要给定了长m和高n,那么要从左下角走到右上角,不管怎么走,一定要往右走m次,往上走n次例如给定 m=5,n=4那么可以 上上上上上右右右右又转载 2015-08-26 10:04:58 · 672 阅读 · 0 评论 -
POJ-1019-Number Sequence-组合数学
这题一定要读懂题,读不懂题就…… o(︶︿︶)o 唉 说多了都是泪啊~~~~题目大意:一个数字序列,规律是这样的:1 12 123 1234 12345 123456 1234567 12345678 123456789 12345678910 1234567891011 123456789101112······k求这个序列中的第多少位是什么数字。 注意 :12转载 2015-08-26 08:41:57 · 535 阅读 · 0 评论 -
POJ -2635-The Embarrassed Cryptographer-数论
题意: 给你一个数n,k,如果n有小于k的素数因子,就输出,没有的话输出GOOD思路: 求一个10^100 的K 对 小于 10^6的 L 取余,问2-L-1 之间能否有能整除K的素数。设k=a0a1a2a3a4a5a6a7a8a9a10.k % m =a0a1a2a3a4a5a6*1000 %m + a7a8a9a10%m =(a0a1a2*100原创 2015-08-26 15:47:17 · 533 阅读 · 0 评论