Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9129 Accepted: 3391 Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a boolean operator op (one of AND, OR, XOR) and an integer c…
Dijkstra模板题,也可以用Floyd算法. 关于Dijkstra算法有两种写法,只有一点细节不同,思想是一样的. 写法1: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #define Mod 1000000007 using namespace std; #define N 1007 int mp…
<题目链接> 题目大意:用k种颜色对n个珠子构成的环上色,旋转.翻转后相同的只算一种,求不等价的着色方案数. 解题分析: 对于这种等价计数问题,可以用polay定理来解决,本题是一道polay定理的模板题. 具体polay定理的实现步骤如下(选自算法入门经典训练指南  147页): #include<iostream> #include<stdio.h> using namespace std; typedef long long LL; int n, m; int g…
Given a connected undirected graph, tell if its minimum spanning tree is unique. Definition 1 (Spanning Tree): Consider a connected, undirected graph G = (V, E). A spanning tree of G is a subgraph of G, say T = (V', E'), with the following properties…
后缀数组: #include<cstdio> #include<algorithm> #include<cstring> #include<vector> using namespace std; typedef long long ll; ,mod=; char s[N]; ],Log[N]; void Sort(int* x,int* y,int m) { ; i<m; ++i)c[i]=; ; i<n; ++i)++c[x[i]]; ; i…
Description Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep, so she wants to get back as quickly as possible. Farmer Joh…
Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10841   Accepted: 5085 Description A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are called the…
一条边<u,v>表示u选那么v一定被选. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; ; ; struct EDGE{int to,next;}edge[Maxm]; int T,m,Stack[Maxn],head[Maxn],Belong[Maxn],Id[Maxn],Dfn[Maxn],L…
Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9987   Accepted: 3741 Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a boolean operator op (one of AND, OR, XOR) and an integ…
Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 6778 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computer…
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes…
题目链接:http://poj.org/problem?id=3286 题目大意: 输入n,m,求[n,m]的所有数字中,0出现的总数是多少,前导零不算. 解题思路: 模板题,设dp[pos][num],pos为数位,num为当前0的数目,然后套数位DP模板即可. 还有之前的一些思考: 关于数位DP求0时,dp下标记录num有什么作用,num不是与后面的0的个数无关吗?是的,在(!limit&&!lead)的情况下,前面有多少0是不影响后面可以出现多少0的.但是,比如说dp[pos][nu…
http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41051   Accepted: 16547 Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a mem…
http://poj.org/problem?id=3264 题意:给出n个数,还有q个询问,询问[l,r]区间里面最大值和最小值的差值. 思路:RMQ模板题,开两个数组维护最大值和最小值就行. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50010 #define INF 0x3f3f3f3…
POJ 1741. Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 34141   Accepted: 11420 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and…
Sliding Window POJ - 2823 单调队列模板题 题意 给出一个数列 并且给出一个数m 问每个连续的m中的最小\最大值是多少,并输出 思路 使用单调队列来写,拿最小值来举例 要求区间最小值 就是维护一个单调递增的序列 对于样例 8 3 1 3 -1 -3 5 3 6 7 我们先模拟一遍 1.队列为空 1 进队 队列:1 2.3>队尾元素 3 进队 队列: 1 3 3.-1小于队尾元素,一直从尾部出队知道找到比-1小的元素或者队列为空 队列:-1 当队列中元素大于m的时候从队头删…
传送门:http://poj.org/problem?id=1287 题意:给出n个点 m条边 ,求最小生成树的权 思路:最小生树的模板题,直接跑一遍kruskal即可 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<string.h> using namespace std; const int maxn = 5005; struct node { int u; in…
传送门:http://poj.org/problem?id=1860 题意:给出每两种货币之间交换的手续费和汇率,求出从当前货币s开始交换回到s,能否使本金增多. 思路:bellman-Ford模板题.直接跑一遍,判断是否存在正环就好了.(复杂度n*m) 代码: #include<iostream> using namespace std; int n; //货币种数 int m; //兑换点数量 int s; //持有第s种货币 double v; //持有的s货币的本金 double di…
传送门:http://poj.org/problem?id=1655 题意:有T组数据,求出每组数据所构成的树的重心,输出这个树的重心的编号,并且输出重心删除后得到的最大子树的节点个数,如果个数相同,取编号小 的 思路:树的重心的模板题 首先要知道什么是树的重心,树的重心定义为:找到一个点,其所有的子树中最大的子树节点数最少,那么这个点就是这棵树的重心,删去重心后,生成的多棵树尽可能平衡.   所以寻找重心,即是最小化重心的最大子树.子树大小的计算分为两部分 的下面的子树大小,即可计算出 的上面…
题目链接:http://poj.org/problem?id=3678 代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> using namespace std; ; struct Two_Sat { int n; vector<]; ]; ],cnt; void init(int n) { this-…
Description Katu Puzzle ≤ c ≤ ). One Katu ≤ Xi ≤ ) such that for each edge e(a, b) labeled by op and c, the following formula holds: Xa op Xb = c The calculating rules are: AND 0 1 0 0 0 1 0 1 OR 0 1 0 0 1 1 1 1 XOR 0 1 0 0 1 1 1 0 Given a Katu Puzzl…
http://poj.org/problem?id=3678 给m条连接两个点的边,每条边有一个权值0或1,有一个运算方式and.or或xor,要求和这条边相连的两个点经过边上的运算后的结果是边的权值.问存不存在使所有边都符合条件的给点赋值的方法. 2-SAT的各种连法都有了. #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath…
http://poj.org/problem?id=3678 题目大意:就是给你n个点,m条边,每个点都可以取值为0或者1,边上都会有一个符号op(op=xor or and三种)和一个权值c.然后问你如何选择每个点的值,才能让所有点都满足x[i] op x[j] = c 思路: 这题学会了好多东西哇,至少我明白了xor,or,and这些关系如何建图拉 //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #include<cstdio> #include<…
Description 给出一个关系,包括 And,Xor,Or 问是否存在解. Sol 经典的2-SAT问题. 把每个值看成两个点,一个点代表选 \(0\) ,另一个代表选 \(1\) . 首先来看 Xor : 如果两个值异或起来为 \(1\) :那么连边 \((i_0,j_1),(i_1,j_0),(j_0,i_1),(j_1,i_0)\) . 否则 连边 \((i_0,j_0),(i_1,j_1),(j_0,i_0),(j_1,i_1)\) . 然后是 And. 如果两个值 And 起来为…
题目链接 题意:给出a, b, c 和操作类型 (与或异或),问是否满足所有的式子 主要是建图: 对于 and , c == 1: 说明 a 和 b都是1,那么 0 就不能取, a' -> a , b' - > b ,因为 a 和 a'是对立事件,对于 a' - >a说明,a'如果成立,那么a也一定存在,显然这是不可能的所以a'不会 成立的. c == 0 说明 a 和 b不全为1, a' -> b , b' -> a 对于 or,  c == 1 :说明 a 和 b 不全为…
题意: 不说了..典型的2-SAT 常用模型: 重点: 突出"绑定性". 连线表示限制而非可行. 因为最后要求对立点不在同一强连通分量是说同一强连通中的点必须同时选. 坑: 首先是算法记错了...inq是求SPFA用的... Tarjan中也少了个灰色点黑色点的判断(本身算是查漏补缺吧, 以后检查的时候首先还是看看模板有没有背错)... 分身点加的是点的个数. 异或0的那个判断粗心了... 还是默认多组样例吧... #include <cstdio> #include &l…
传送门:Problem 3678 https://www.cnblogs.com/violet-acmer/p/9769406.html 难点: 题意理解+构图 题意: 有n个点 v[0,2......,n-1](v[i]值为0或1),边(a[i],b[i])间的权值为c[i],现在给出它们之间的一些逻辑运算的结果(比如c[1]=a[1] & b[1] = 1),逻辑运算有AND OR XOR三种,问是否存在一种满足所有条件的取值方案. 构图难点: 如果类似 u v 1 AND这样的数据,说明u…
Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6553   Accepted: 2401 Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a boolean operator op (one of AND, OR, XOR) and an integ…
思路:将每个点拆分为两个点 a与a' ,a表示为1,a'表示为0.那么条件给的每个边自然就会存在矛盾,然后根据2-SAT建边就行了. #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cmath> #include<vector> #define Maxn 3010 #define Maxm 1000000 using…
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #include<queue> #include<cmath> #include<stack> using namespace std; #define Maxn 1010 #define Maxm 1000010 ]; int…