POJ
Sqwlly
有自己热爱的东西,真好。
展开
-
POJ 1556 The Doors(计算几何+最短路)
POJ 1556 The Doors题意:在一个矩形里,从(0,5)→(10,5)(0,5)\rightarrow(10,5)(0,5)→(10,5)的最路径,中间会有n座墙,每个墙有两个门。题解:把所有的门的点坐标预处理出来,把墙看成线段,从起点开始往后连边建图,对于没有被墙阻隔的连边,然后跑个最短路即可。代码/**************************************...原创 2019-11-02 13:27:14 · 309 阅读 · 0 评论 -
POJ 2142 The Balance(扩展欧几里德)
The Balance由题意可得:{ax1−by1=dbx2−ay2=d\begin{cases}ax_1 - by_1 = d \\\\ bx_2 - ay_2 = d\end{cases}⎩⎪⎨⎪⎧ax1−by1=dbx2−ay2=d用exgcdexgcdexgcd解出两个最小解,然后输出最小的那一对即可。注意如果x2+y2x_2 + y_2x2+y2更小要先输出y2y_...原创 2018-12-11 01:11:05 · 197 阅读 · 0 评论 -
POJ 3420 Quad Tiling 状压DP+递推+矩阵快速幂
Quad Tiling题解:首先根据题目数据量来看,肯定是必须有递推公式的了或者滚动数组什么的。因此我们考虑递推情况,对于4⋅n4\cdot n4⋅n,最后一列的放置情况。如果是444个[1⋅2][1\cdot 2][1⋅2]排列,那么dp[n]=dp[n−2]dp[n] = dp[n - 2]dp[n]=dp[n−2]。如果是222个[2⋅1][2\cdot 1][2⋅1]排列,那么d...原创 2018-12-11 00:36:23 · 192 阅读 · 0 评论 -
POJ 1061 青蛙的约会(扩展欧几里德)
青蛙的约会题解:显然可以列出方程(x+k⋅m)%L=(y+k⋅n)%L(x+k\cdot m)\%L=(y+k\cdot n)\%L(x+k⋅m)%L=(y+k⋅n)%L然后可以转换为(m−n)⋅a+L⋅b=y−x(m-n)\cdot a+L\cdot b=y-x(m−n)⋅a+L⋅b=y−x,最后求最小正整数解。exgcdexgcdexgcd了呀~代码#include<iostre...原创 2018-12-10 23:37:39 · 189 阅读 · 0 评论 -
POJ 3411 Paid Roads (状压DP)
Paid Roads题意:111到nnn的最小花费,aaa到bbb的花费为,如果经过ccc为ppp,否则为rrr。题解:dp[i][j]dp[i][j]dp[i][j]表示以jjj结尾状态为iii时的最小花费,则有dp[i∣1<<a][b]=min(dp[i∣1<<a][b],dp[i][a]+C[ i>&...原创 2018-12-04 00:05:22 · 234 阅读 · 0 评论 -
POJ2836 Rectangular Covering(状压dp)
Rectangular Covering题解:先预处理出所有的矩形吧。然后将每个矩形所涵盖的点也处理出来。最后再dpdpdp。dp[s]dp[s]dp[s]表示矩形集合为sss的时候的最小面积。则有dp[s∣j]=min(dp[s∣j],dp[s]+a[j].area)dp[s|j] = min(dp[s|j],dp[s] + a[j].area)dp[s∣j]=min(dp[s∣j],dp[...原创 2018-11-25 21:24:12 · 194 阅读 · 0 评论 -
POJ3254 Corn Fields(状压dp)
Corn Fields题解:先预处理出所有可行的状态。然后初始第一行,从第二行开始枚举每一行所有可行的状态,对于每种可行状态再枚举与上一行的状态是否冲突。dp[i][j]dp[i][j]dp[i][j]表示第iii行状态为jjj的时候的方法数。则有dp[i][j]=dp[i][j]+dp[i−1][k](state[j]&state[k]==0)dp[i][j] =dp[i][...原创 2018-11-25 20:54:49 · 168 阅读 · 0 评论 -
POJ 2441 Arrange the Bulls(状压dp)
Arrange the Bulls题解:本题可能就考验的是对位运算的掌握叭…dp[s]dp[s]dp[s]表示在状态为sss的情况下满足方案的个数。首先满足第一个球队喜欢的场地,然后枚举场地集合,就有如果iii喜欢jjj并且已有集合sss里还未存在jjj,则dp[s∣j]=dp[s∣j]+dp[s]dp[s | j] = dp[s | j] + dp[s]dp[s∣j]=dp[s∣j]+dp[...原创 2018-11-25 19:32:53 · 202 阅读 · 0 评论 -
POJ 1185 炮兵布阵(状压dp)
炮兵布阵题解:先考虑一维的情况,dp[i]dp[i]dp[i]前iii行所最多能摆放的炮兵部队的数量,显然无法满足无后效性,无法递推。再考虑加一维,dp[i][j]dp[i][j]dp[i][j]表示第iii行布局为jjj的情况下所最多能摆放的炮兵部队的数量,此时依然无法递推,因为每一个炮兵影响的范围是前后两格和左右两格,所以在第i−1i-1i−1行布局为kkk的时候无法分辨与布局jjj是否相容...原创 2018-10-24 19:09:52 · 207 阅读 · 0 评论 -
POJ1753 Flip Game(暴力枚举)
Flip Game题解:因为数据只有4⋅44\cdot 44⋅4,dfsdfsdfs暴力枚举每种情况即可。翻硬币次数最多不会超过161616次,因为翻两次相当于没有翻。代码#include<iostream>using namespace std;bool a[6][6];bool check(){ char pre = a[0][0]; for(int i = ...原创 2018-10-14 23:39:09 · 264 阅读 · 0 评论 -
POJ 1611(基础并查集)
The Suspects问题分析基础并查集,就是加了个人数统计。#include <cstdio>using namespace std;const int N = 3e4+3;int n,m,k, total[N], f[N], father, son;int GetF(int v){ if(f[v]==v){ return...原创 2018-07-27 18:47:58 · 396 阅读 · 0 评论 -
POJ 1731(递归方式|next_permutation())
OrdersTime Limit: 1000MS Memory Limit: 10000KDescriptionThe stores manager has sorted all kinds of goods in an alphabetical order of their labels. All the kinds having labels starting with ...原创 2018-03-28 22:45:00 · 271 阅读 · 0 评论 -
POJ 1276(多重背包+二进制优化)
Cash MachineTime Limit: 1000MS Memory Limit: 10000KDescriptionA Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cas...原创 2018-04-08 09:34:27 · 332 阅读 · 0 评论 -
POJ 3669(BFS)
Meteor ShowerTime Limit: 1000MS Memory Limit: 65536KDescriptionBessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy...原创 2018-03-23 15:39:22 · 234 阅读 · 0 评论 -
POJ 1111(简单dfs)
Image Perimeters原题请点击上方蓝色标题 ↑ 题意:求最大连通块的周长,统计连通块周围的点点即可,所以我们预先将map都初始化为点点,然后dfs去搜索就好,上下左右四个方向,每有一个点点周长就加一。 ok,直接上AC code。#include<algorithm>#include<iostream>#include<string.h...原创 2018-03-22 17:25:43 · 249 阅读 · 0 评论 -
POJ 3070(矩阵快速幂,求斐波那契第n项)
FibonacciTime Limit: 1000MSMemory Limit: 65536KDescriptionIn the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibon...原创 2018-03-10 17:47:33 · 413 阅读 · 0 评论 -
POJ 1163(数字三角形+动态规划)
The TriangleTime Limit: 1000MS Memory Limit: 10000KDescription7 3 8 8 1 0 2 7 4 4 4 5 2 6 5(Figure 1)Figure 1 shows a number triangle. Write a program that cal...原创 2018-02-22 12:18:19 · 912 阅读 · 0 评论 -
POJ 3210(逻辑推理)
CoinsTime Limit: 1000MS Memory Limit: 131072KDescriptionSnoopy has three coins. One day he tossed them on a table then and tried to flip some of them so that they had either all heads or ...原创 2018-02-18 13:37:16 · 700 阅读 · 0 评论 -
POJ 1458(最长公共子序列)
Common SubsequenceTime Limit: 1000MSMemory Limit: 10000KDescriptionA subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = &...原创 2018-02-26 13:01:03 · 1999 阅读 · 0 评论