
poj
文章平均质量分 63
Mininda
云雀叫了一整天
展开
-
【poj3617】Best Cow Line 贪心
Best Cow LineTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 26954 Accepted: 7284DescriptionFJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual原创 2017-11-08 09:16:55 · 305 阅读 · 0 评论 -
【poj2279】Mr. Young's Picture Permutations dp
DescriptionMr. Young wishes to take a picture of his class. The students will stand in rows with each row no longer than the row behind it and the left ends of the rows aligned. For instance, 12 stud...原创 2018-10-24 07:32:45 · 451 阅读 · 0 评论 -
【poj2155】Matrix 树状数组
题目大意给定一个N*N的矩阵a,a矩阵的初值设为0。T次操作,涉及区间翻转0和1以及单点查询。2 <= N <= 1000, 1 <= T <= 50000题解我的做法好像跟其他人不太一样qwq用二维树状数组维护差分,每次(x1,y1)+1,(x2+1,y1)-1,(x1,y2+1),因为右下部分多减了了一次,所以(x2+1,y2+1)+1,然后询问的时候只要加起...原创 2018-10-03 18:13:09 · 302 阅读 · 0 评论 -
【poj2689】Prime Distance 素数
题意:给出了T组询问,每次询问给出L,R,求出每次[L,R]间相差最大以及最小的相邻素数。题解:由于L,R都很大所以没法直接用欧拉筛筛到。但是我们注意到L,R的差为1e6,可以用数组存下。并且我们可以知道任意一个合数n都拥有一个不大于sqrt(n)的素因数,所以我们可以预处理出1~2^16的所有质数,每次用这些质数筛出来l,r区间的质数,并且存在数组[0,u-l]中即可。#inclu...原创 2018-07-30 19:01:28 · 409 阅读 · 0 评论 -
【poj1185】【NOI2001】炮兵阵地 状压dp
又是一道状压dp经典题!#include<iostream>#include<cctype>#include<cstdio>#include<cstring>#define M 1<<10#define N 105using namespace std;int dp[N][N][N],mp[N],a[N],b[...原创 2018-07-22 00:02:29 · 273 阅读 · 0 评论 -
【poj2411】Mondriaan's Dream 状压dp
又是一道状压dp入门经典题!dp[i][j]表示第i行的状态为j时的状态数。1表示放个竖着的。首先预处理判断与0的个数,因为只有偶数的时候才能放横着的,转移的时候只要与之前状态逻辑与一下为0并且逻辑或一下的状态有偶数个0(逻辑与一下是因为之前状态竖着的)就是符合条件的,目标是dp[n][0]。记得开long long#include<iostream>#include&...原创 2018-07-21 23:42:19 · 266 阅读 · 0 评论 -
【poj1845】Sumdiv 递归+数学
这题很有意思。首先根据唯一分解定理我们可以得知a=p1^k1*p2^k2*k3......pn^kn,然后将所有的因数加起来再用一下乘法结合律就成了(p1^0+p1^1+p1^2......+p1^k1)......(pn^0+.......+pn^kn)这样一个式子,但是就成了求每一个的等比公式求和。但是不能直接使用公式,因为%并不适用于除法,所以:p^0+p^1+p^2......+p^k...原创 2018-07-21 23:22:30 · 269 阅读 · 0 评论 -
【poj3263】Tallest Cow 前缀和
前缀和水题。因为求最优所以默认最大,每次给出了一对关系,我们都可以知道中间的数要小。前缀和处理一下即可。#include<iostream>#include<map>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;ma...原创 2018-07-21 23:10:49 · 318 阅读 · 0 评论 -
【poj1958】Strange Towers of Hanoi 递推
原题#include<iostream>#include<cstdio>#include<cstring>#include<cctype>#define inf 0x3f3f3f3fusing namespace std;int f[1010],d[1010];int main() { for (int i=1;i<=13...原创 2018-07-16 22:59:28 · 221 阅读 · 0 评论 -
【poj2752】Seek the Name, Seek the Fame kmp
题意:给你一个字符串,输出所有不同的前缀后缀字符串(即是前缀又是后缀)的长度。题解:运用kmp中的next数组的思想递推一下即可。//poj2752 Seek the Name, Seek the Fame#include<iostream>#include<algorithm>#include<string>#include<cstring>...原创 2018-02-18 15:39:46 · 265 阅读 · 0 评论 -
【LCA倍增模板】【poj1330】最近公共祖先
Nearest Common AncestorsTime Limit: 1000MSMemory Limit: 10000KTotal Submissions: 31027Accepted: 15800DescriptionA rooted tree is a well-known data struc原创 2017-11-01 23:27:43 · 306 阅读 · 0 评论 -
【poj2487】Farey Sequence 欧拉函数
欧拉函数模板欧拉函数的三个性质1 当q为质数时f(q)=q-12 如果i/p是p的质数时f(i)=f(i/p)*p3 如果i/p不是p的质数时f(i)=f(i/p)*(p-1)原创 2017-11-08 22:05:59 · 273 阅读 · 0 评论 -
【poj1852】Ants 乱搞
因为蚂蚁碰头之后速度啥的都没变,只是方向变了。那么就相当于两只蚂蚁擦肩而过。(好好理解一下)这样问题就很好解决了。原创 2017-11-09 22:31:19 · 308 阅读 · 0 评论 -
【poj2367】Genealogical tree 拓扑排序
Genealogical treeTime Limit: 1000MS Memory Limit: 65536K Total Submissions: 6167 Accepted: 4070 Special Judge DescriptionThe system of Martians' blood relations i...原创 2017-11-09 20:53:01 · 302 阅读 · 0 评论 -
【poj1222】EXTENDED LIGHTS OUT 模拟
如果我们枚举每一个灯开还是关就是2^30显然不可行。我们就要想该如何优化使枚举数尽可能的变小。我们先假设第一列已经固定了。那么想要改变第一列的状态只能通过改变第二列的状态。如果第一列有灯没关,在第二列的同一行这个按钮必须按下。以此类推,如果第一列确定,那么后面每一列就已经确定了。所以我们只需要枚举第一列即可,瞬间缩到2^5=32次。原创 2017-11-08 15:02:30 · 302 阅读 · 0 评论 -
【poj3662】Telephone Lines 二分答案+spfa
题意给定一个无向图,求点1~n的一个路径,使路径上第k+1条路的边权尽量小。题解因为花费多的答案一定包括花费少的答案,具有单调性。所以我们可以用二分答案来求解。每次将小于等于mid的边设为0,大于mid的边设为1。spfa跑一下,如果dist[n]不大于k就满足。代码#include<iostream>#include<queue>#include<cs...原创 2018-11-07 10:32:34 · 385 阅读 · 0 评论