
POJ
文章平均质量分 70
ahfywff
这个作者很懒,什么都没留下…
展开
-
POJ 2886 Who Gets the Most Candies?
题意: N个孩子顺时针坐成一个圆圈且从1到N编号,每个孩子手中有一张标有非零整数的卡片。第K个孩子先出圈,如果他手中卡片上的数字A大于零,下一个出圈的是他左手边第A个孩子。否则,下一个出圈的是他右手边第(-A)个孩子。第p个出圈的孩子会得到F(p)个糖果,F(p)为p的因子数。求得到糖果数最多的是哪个孩子及得到多少糖果。 分析: 出圈过程有点类似约瑟夫环。假设当前出圈的是剩余孩原创 2012-01-31 15:17:07 · 2257 阅读 · 4 评论 -
POJ 3368 Frequent values [Segment Tree]
给你一个非递减的序列,再给你一些区间,问你每个区间里出现次数最多的数字出现了几次。Sample Input10 3-1 -1 1 1 1 1 3 10 10 102 31 105 100Sample Output143由于所给序列是非递减的,可以把连续的相同数字看成一段连续的区间,所以本题可以转化为求区间内的最长连续子区间。#inclu原创 2012-05-22 19:04:56 · 531 阅读 · 0 评论 -
POJ 3264 Balanced Lineup [RMQ]
求区间最大值与最小值之差。#include #include #include #include #include using namespace std;const int maxn = 50010;int n, q, a, b;int minh[maxn][16]; // minh[i][j]: h[i]~h[i+(1<<j)-1]的最小值 int maxh[maxn原创 2012-05-23 21:45:28 · 403 阅读 · 0 评论 -
POJ 2019 Cornfields [二维RMQ]
二维RMQ。求一个矩阵的子矩阵各元素的最大值与最小值之差。用int会超内存,改用short。#include #include #include #include #include using namespace std;const int maxn = 255;int n, b, k;short dpmin[maxn][maxn][10][10];short dpm原创 2012-05-24 12:24:40 · 1170 阅读 · 0 评论 -
POJ 2452 Sticks Problem [RMQ+二分]
/*题意:给你一组数a[n],求满足a[i] < a[k] < a[j] (i <= k <= j)的最大的j-i。解法:RMQ + 二分。枚举i,利用二分求出a[i]右边第一个小于a[i]的数的位置k,再求出[i, k]中最大值的位置j,若a[j] > a[i],则更新结果。*/#include #include #include #include #include u原创 2012-05-24 19:11:00 · 1821 阅读 · 0 评论 -
POJ 1330 Nearest Common Ancestors [LCA+RMQ]
LCA的入门题,我用的是ST在线算法和Tarjan离线算法。ST:#include #include #include #include #include #include using namespace std;const int maxn = 10010;int t, n, cnt;vector son[maxn];int parent[maxn];bool vi原创 2012-05-25 21:38:38 · 834 阅读 · 1 评论 -
POJ 1470 Closest Common Ancestors [LCA+RMQ]
这题的输入有点恶心,OLE很多次才过。。。ST:#include #include #include #include #include #include using namespace std;const int maxn = 10010;int n, q, cnt;vector son[maxn];int parent[maxn];bool vis[maxn];原创 2012-05-25 23:42:37 · 559 阅读 · 0 评论 -
POJ 1986 Distance Queries [LCA]
#include #include #include #include using namespace std;const int maxn = 40010;const int maxk = 10010;int n, m, k;int cnt1, cnt2;int head1[maxn], head2[maxn];int set[maxn], an[maxn];int d原创 2012-05-26 16:28:01 · 553 阅读 · 0 评论 -
POJ 3481 Double Queue【SBT】
http://poj.org/problem?id=3481该SBT模板只实现了一些简单的操作,我会不断完善其它功能。#include #include #include #include #include using namespace std;const int maxn = 100010;struct Node { int key, val;原创 2012-09-27 23:50:28 · 1092 阅读 · 0 评论 -
POJ 4045 Power Station 2012金华邀请赛B题(树形DP)
很早就听说过树形DP了,只是一直没做过这方面的题。这次金华邀请赛出了这道树形DP,是zz_1215做出来的。发现这个考的挺多的,于是就学习了一下。这个题大致意思是给你一颗树,让你求一点,使该点到其余各点的距离之和最小。如果这样的点有多个,则按升序依次输出。我的做法:对于点x定义两个量dp[x]和node[x]。 dp[x]为以节点x为根的子树中x到它后代节点的距离之和;no原创 2012-05-14 15:45:16 · 2690 阅读 · 0 评论 -
poj 3469 Dual Core CPU (最小割->最大流)
这题不难,很容易建立最小割模型,然后就是最大流啦。顺便贴上我的SAP模板,此模板是我参考了网上众牛的模板写的,集各种优化于一身。#include #include #include #include #include using namespace std;const int maxn = 20010;const int maxm = 999999;const int oo =原创 2012-02-06 15:44:45 · 628 阅读 · 0 评论 -
poj 1273 Drainage Ditches (第一道网络流~)
网络流入门题,注意可能有重边。#include #include #include #include using namespace std;const int maxn = 210;int c[maxn][maxn], pre[maxn], f[maxn][maxn];int n, m, add;bool bfs(){ queue Q; memset原创 2012-02-05 11:26:15 · 618 阅读 · 2 评论 -
poj 3281 Dining (最大流)
POJ 3281 Dining 这题WA了两次。刚开始我建的图是: s→食物→牛→饮料→t ,但这样不能保证每头牛最多只得到一种食物和一种饮料,WA了。后来又想了一下,按照以下方式建图:s→食物→牛→牛→饮料→t,这样就能保证每头牛最多只得到一种食物和一种饮料。心想这回肯定能AC的,谁知提交上去还是一个WA。我又仔细检查了一下代码,惊奇的发现是数组开小了,这个真不应该~#include原创 2012-02-07 08:51:25 · 1169 阅读 · 0 评论 -
poj2526 Minimum Cost (费用流)
题意:有M个供应商,N个售货商和K种商品。给出每个售货商需要的每种商品的数量,每个供应商拥有的每种商品的数量以及将第k种商品从第i个供应商运到第j个销售商所需的费用。若销售商的需求能得到满足,输出所需的最小费用;否则,输出-1。刚开始,我把每个供应商和销售商拆成2K个点,结果超时了。后来,对于每种商品分别建图和求最小费用,累加既得所需总费用,最终AC。首先,先统计每种商品的原创 2012-02-24 12:51:45 · 673 阅读 · 0 评论 -
poj1027 The Same Game (简单模拟题)
一开始搜索部分用的是BFS,竟然MLE啦!谁能告诉我为什么?改成DFS后AC了。。。题目要仔细阅读,否则会漏掉一些信息~~/* * ===================================================================================== * * Filename: poj1027_The_Same_G原创 2012-02-25 18:28:14 · 1551 阅读 · 0 评论 -
poj1149 PIGS (最大流)
题意:有m个猪圈和n个顾客,每个猪圈里都有一定数量的猪,每个顾客都想购买一定数量的猪。每位顾客可以打开其中某些特定的猪圈,然后买猪,该顾客打开的猪圈里的猪可以被重新分配。求最多能卖出多少头猪。分析:把每个顾客和每个猪圈都看成一个点,添加源点S和汇点T。源点S与每个顾客之间添加一条边,容量为该顾客要购买的猪的数目。每个猪圈与汇点T之间添加一条边,容量为该猪圈初始的猪的数量。若第j位顾客与原创 2012-02-26 14:29:27 · 345 阅读 · 0 评论 -
poj3680 Intervals
先把区间端点离散化为n个点,再添加源点s和汇点t。s向第一个点连边,容量为k,费用为0;第i个点向第i+1个点连边,容量为oo,费用为0;第n个点向t连边,容量为k,费用为0。假如某个区间端点离散成a,b,则由a向b连边,容量为1,费用为-w(w为该区间的权值)。然后对该网络求最小费用最大流~~#include #include #include #include #include #i原创 2012-02-29 22:22:49 · 952 阅读 · 0 评论 -
poj1386 Play on Words (欧拉路径)
~判断有向图是否存在欧拉路径~#include #include #include #include using namespace std;int father[26], rank[26];int in[26], out[26];bool has[26];int t, n;int find(int x){ if (x != father[x]) { fath原创 2012-03-05 15:19:22 · 1416 阅读 · 0 评论 -
POJ 1509 Glass Beads【后缀自动机、最小表示法】
此题为最简单的后缀自动机的应用。#include #include #include #include #include using namespace std;const int maxn = 10010;struct SamNode { int ch[26]; int par, len; void Init() { par =原创 2012-10-07 17:13:32 · 2465 阅读 · 1 评论