
POJ
文章平均质量分 75
深海沧澜夜未央
这个作者很懒,什么都没留下…
展开
-
POJ - 1456 Supermarket 贪心+并查集 /小根堆
A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment th...原创 2018-08-02 15:40:51 · 410 阅读 · 0 评论 -
POJ 1703 Find them, Catch them 并查集 (关系问题 判断是否在一个集合)
DescriptionThe police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to ident...原创 2018-02-19 10:38:29 · 321 阅读 · 0 评论 -
POJ 2528 Mayor's poster 线段树离散化
DescriptionThe citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council h...原创 2018-02-08 11:03:59 · 220 阅读 · 0 评论 -
POJ 3468 A Simple Problem with Integers 线段树区间更新 (lazy策略 值在基础上相加或相减)
DescriptionYou have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ...原创 2018-02-08 09:37:47 · 234 阅读 · 0 评论 -
POJ 1182 食物链 并查集 (关系问题)
动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述: 第一种说法是"1 X Y",表示X和Y是同类。 第二种说法是"2 X Y",表示X吃Y。 此人对N个动物,用上述两种说法,一句接一句地说出K句话,这K句话有...原创 2018-02-14 12:38:55 · 255 阅读 · 0 评论 -
POJ 2524 宗教信仰 并查集 基础模板
世界上有许多不同的宗教,现在有一个你感兴趣的问题:找出多少不同的宗教,在你的大学中的大学生信仰了多少种不同的宗教。你知道在你的大学有n个学生(0<n<= 50000)。若直接问每一个学生的宗教信仰不大适合。此外,许多学生还不太愿意说出自己的信仰。有一种方法来避免这个问题,询问m(0<=m<=n(n- 1)/ 2)对学生,询问他们是否信仰同一个宗教(比如,可以询问他们是否都参...原创 2017-05-30 13:41:10 · 748 阅读 · 0 评论 -
POJ 2236 Wireless Network 并查集基础
题目描述一场地震在东南亚发生了。不幸的是ACM组织通过电脑建立的无线网络遭到了毁灭性的影响—--网络中所有的电脑都损坏了。在陆续的维修电脑之后,无线网络有逐渐开始再一次运作了。由于硬件的制约,每两台电脑只能保持不超过d米的距离,才可以直接进行通讯。但是每台电脑又可以作为其它两台电脑通讯的中介点,也就是说假设A电脑与B电脑不在能直接通讯的的范围内,但是它们可以通过同时能与A和B电脑通讯的C电脑建立间...原创 2017-05-30 13:43:54 · 549 阅读 · 0 评论 -
POJ 3264 Balanced Lineup 区间查询(两棵树求最大最小值)
For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things ...原创 2018-02-09 11:14:11 · 677 阅读 · 0 评论 -
POJ - 3260 The Fewest Coins ( 多重背包 min 价值为1)
Farmer John has gone to town to buy some farm supplies. Being a very efficient man, he always pays for his goods in such a way that the smallest number of coins changes hands, i.e., the number of coin原创 2018-02-02 10:53:38 · 277 阅读 · 0 评论 -
POJ 1276 Cash Machine ( 多重背包模板题目 )
DescriptionA Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The machine uses exactly N distinct bill denomin原创 2018-01-31 23:15:41 · 279 阅读 · 0 评论 -
POJ 2392 Space Elevator ( 多重背包 背包限制不同 + 贪心 )
DescriptionThe cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks with which原创 2018-02-01 00:11:10 · 444 阅读 · 0 评论 -
POJ 1308 Is It A Tree? 并查集 (判断任意2个点是否有且仅有一条路径可以相通)
A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following properties. There i...原创 2018-02-19 10:46:20 · 233 阅读 · 0 评论 -
POJ - 1321 棋盘问题(类似N皇后)
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n 当为-1...原创 2018-06-19 11:35:39 · 230 阅读 · 0 评论 -
POJ 3190 -Stall Reservations 小根堆 贪心 区间问题
Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise time interval A..B (1 <= A <= B <= 1,000,000), which includes both times ...原创 2018-08-02 15:15:59 · 317 阅读 · 0 评论 -
POJ - 3764 The xor-longest Path 字典树+异或
题意:给定一棵N个节点的树,树上的每条边都有一个权值,从树中选择两个点x和y,把从x到y路径上的所有边权xor异或起来,得到的最大结果是多少。思路:相同部分异或为0,所以从x到y路径上的边权的xor结果为D[x] xor D [y] ,将x到根与y到根的重叠部分恰好抵消掉。可以先用DFS得到所有的D[x],然后题目变成了D[1]-D[i] 选两个数字异或的结果最大...原创 2018-07-31 15:51:09 · 280 阅读 · 0 评论 -
POJ 2054 /HDU 1055 Color a Tree(贪心+并查集)
Bob is very interested in the data structure of a tree. A tree is a directed graph in which a special node is singled out, called the "root" of the tree, and there is a unique path from the root to ea...原创 2018-07-27 15:46:36 · 318 阅读 · 1 评论 -
POJ - 3974 Palindrome 最长的回文子串 3种不同的方法 字符串hash/Manacher算法
Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, "Can you propose an efficient algorithm to find the length of the lar...原创 2018-07-30 10:50:42 · 1206 阅读 · 0 评论 -
POJ - 3349 Snowflake Snow Snowflakes hash 判断六角是否相同
You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Your program will read information about a collection of snowflakes, and ...原创 2018-07-30 10:32:20 · 245 阅读 · 0 评论 -
POJ 2482 线段树 离散化 扫描线 矩阵最大权值
题意:给出n个星星的坐标,每个星星有一个亮度,给出一个矩形的长和宽,问矩形能包括的星星的最大亮度和(不包括边框)。思路: 平面上有若干个区域,每个区域都带有一个权值,求在那个实际上重叠的区域权值和最大。使用扫描线算法,取出每个区域的左右边界,保存2个四元组,(x,y,y+h,c) (x+w,y,y+h,-c),按照第一维的大小排序。同时关于y建立一颗线段树,维护区间最大值max1,可以认为线段...原创 2018-07-21 09:30:41 · 354 阅读 · 0 评论 -
HDU 1542 POJ 1151 Atlantis 线段树+离散化+扫描线 重叠矩阵面积和
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps describe diff...原创 2018-07-20 17:13:16 · 309 阅读 · 0 评论 -
POJ 2299 Ultra-QuickSort 求原始序列的逆序对数 树状数组+离散化
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 sequence is sorted i...原创 2018-07-19 15:52:17 · 192 阅读 · 0 评论 -
POJ 3784 Running Median 动态求中位数 优先队列 小根堆+大根堆
题意:输入M个数,当已输入的个数为奇数个时输出此时的中位数。一共有M/2+1个中位数要输出,每一行10个。思路:当数字是奇数的时候才输出中位数,所以是数组的一半我们可以用小跟堆+大根堆来进行维护,设当前序列长度为M,我们始终保持1--M/2的数字存储在大根堆中(从大到小),M/2+1--M的数字存储在小根堆中,当某一个堆中的元素过多的时候,取出该堆的堆顶入另外一个堆。所以,中位数为小根堆的...原创 2018-07-24 18:10:31 · 661 阅读 · 0 评论 -
POJ - 2018 Best Cow Fences (二分 连续数的平均和+前缀和)
Farmer John’s farm consists of a long row of N (1 <= N <= 100,000)fields. Each field contains a certain number of cows, 1 <= ncows <= 2000.FJ wants to build a fence around a contiguous g...原创 2018-07-24 10:54:43 · 1125 阅读 · 1 评论 -
POJ - 2184 Cow Exhibition (01背包 中 负数的处理)
"Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - Cows with Guns by Dana Lyons The cows want to prove to the public that they are both smart and fun. In order to do this, ...原创 2018-01-24 16:23:27 · 623 阅读 · 0 评论 -
POJ - 3624 Charm Bracelet (01背包 模板 )
Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the原创 2018-01-24 16:13:52 · 248 阅读 · 0 评论 -
POJ 3181 Dollar Dayz (完全背包 + 大数分离输出)
Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for $1, $2, and $3. Farmer John has exactly原创 2018-01-30 21:30:59 · 315 阅读 · 0 评论 -
POJ 3259 Wormholes (Bellman-Ford/SPFA 判断是否存在负权环)
题意:要求判断任意两点都能仅通过正边就可互相到达的有向图中是否存在负权环Bellman-Ford的模板题目。#include #include using namespace std;int F,N,M,W;const int INF = 1<<30;struct Edge{ int s,e,w; Edge(int ss,int ee,int ww)原创 2017-08-08 16:57:57 · 502 阅读 · 0 评论 -
POJ 2975 Nim (Nim的证明)
题意:给定一种Nim状态(相当于含N堆石头),求能有几种方法能通过调整某一堆石头的状态(只准取出),使新的Nim状态为必败态。(或者说求出所给的Nim游戏状态有多少种方法能够赢)思路:Nim结论的应用在证明Nim游戏的SG函数的“根据这个判断被判为N-position的局面一定可以移动到某个P-position”命题时,有这么一段证明:对于某个局面(a1,a2,...,an),若a1^a2原创 2017-08-14 11:21:31 · 264 阅读 · 0 评论 -
POJ 1067 取石子游戏 (威佐夫博奕 Wythoff Game 模板)
Description有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者。Input输入包含若干行,表示若干种石子的初始情况,其中每一行原创 2017-08-14 13:55:53 · 420 阅读 · 1 评论 -
POJ 2484 A Funny Game(规律直推)
Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 6) coins in a circle, as Figure 1 shows. A move consists in removing one or two adjacent coins, leaving all other原创 2017-08-14 14:24:04 · 398 阅读 · 0 评论 -
POJ 2599 A funny game(组合博弈 P/N态+记忆化搜索)
DescriptionThere are several airports in one country, and there are flights between some of them. One can fly from any airport to any other, probably with some changes. For any pair of airports th原创 2017-08-15 12:12:18 · 456 阅读 · 0 评论 -
POJ 2425 A Chess Game(联合组合博弈+树 无向无环图 )
首先介绍下联合组合博弈,联合组合就是多个组合博弈,以 POJ 2599 为例 此题目就是它的联合组合的题目,需要用到SG定理DescriptionLet's design a new chess game. There are N positions to hold M chesses in this game. Multiple chesses can be locate原创 2017-08-15 15:22:54 · 390 阅读 · 1 评论 -
POJ 2960 S-Nim (SG定理的典型应用)
题意:有n堆石头,每堆石头的个数已知,两人轮流从中取石头,每次取石头的个数来自集合S,问先拿者是否有必胜策略思路:SG定理的应用,SG[i]=i(Nim博弈),先求出所有的SG值,贮存在数组中(可以与HDU 1848对比)#include #include #include using namespace std;int s[101];int k;int sg[10050];原创 2017-08-15 21:05:10 · 305 阅读 · 0 评论 -
POJ 1704 Georgia and Bob ( 阶梯博弈 模板 )
Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, number the grids from left to right by 1, 2, 3, ..., and place N chessmen on different grids, as shown in the fo原创 2017-08-16 14:15:50 · 383 阅读 · 0 评论 -
POJ 1740 A New Stone Game (总结发现规律)
题意:n堆石头,2个人轮流操作,操作第一步,从某一堆石头中去除至少一个石头,操作第二步从同一个石头堆中抽任意个或者不抽跳过第二步。思路:总结发现规律,如果石头堆数是奇数则先手必赢,如果是偶数的话,对石头堆从小到大排序,如果每2个一组的石头数都相等的话,先手赢,否则输#include #include #include #include using namespace std;in原创 2017-08-16 17:31:12 · 386 阅读 · 0 评论 -
POJ 2068 Nim (记忆化搜索+组合博弈)
题意:S个石头,双方n个人,每个人最多可以一次拿Si个石头,问先手有没有必胜策略思路:记忆化搜素+组合博弈。(枚举出所有的情况)#include #include #include #include #define N 30#define M 10000using namespace std;int f[N][M],a[N],n,m;// 1为败 0为胜int dfs(i原创 2017-08-17 15:45:49 · 399 阅读 · 0 评论 -
POJ 3159 Candies (差分约束 Dijkstra+优先队列 SPFA+栈)
During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of flymouse’s class a large bag of candies and had flymouse distribute them. All the原创 2017-08-08 15:22:29 · 441 阅读 · 0 评论 -
POJ 3252 Round Numbers(数位 DP 先导零的处理)
这题的约束就是一个数的二进制中0的数量要不能少于1的数量,通过上一题,这题状态就很简单了,dp[pos][num],到当前数位pos,0的数量减去1的数量为num的方案数,一个简单的问题,中间某个pos位上num可能为负数(这不一定是非法的,因为我还没枚举完嘛,只要最终的num>=0才能判合法,中途某个pos就不一定了),这里比较好处理,Hash嘛,最小就-32吧(好像),直接加上32,把32当0转载 2017-10-17 20:20:05 · 398 阅读 · 0 评论 -
POJ 2063 Investment (多轮完全背包 )
John never knew he had a grand-uncle, until he received the notary's letter. He learned that his late grand-uncle had gathered a lot of money, somewhere in South-America, and that John was the only in原创 2018-01-30 21:05:50 · 219 阅读 · 0 评论 -
POJ3250 牛的视野(单调栈)
题意:一群高度不完全相同的牛从左到右站成一排,每头牛只能看见它右边的比它矮的牛的发型,若遇到一头高度大于或等于它的牛,则无法继续看到这头牛和后面的其他牛的发型。给出这些牛的高度,要求每头牛可以看到的牛的数量的和。思路:计算每头牛可以看到牛的头数,可以等效于每头牛可以被看到的次数从左到右依次读取当前牛的高度,从栈顶开始把高度小于或等于当前牛的高度的那些元素删除,此时栈中剩下的元素的数原创 2017-12-29 16:06:16 · 1351 阅读 · 0 评论