POJ 2749--Building roads(2-SAT)】的更多相关文章

HDU 1815, POJ 2749 Building roads pid=1815" target="_blank" style="">题目链接HDU 题目链接POJ 题意: 有n个牛棚, 还有两个中转站S1和S2, S1和S2用一条路连接起来. 为了使得随意牛棚两个都能够有道路联通,如今要让每一个牛棚都连接一条路到S1或者S2. 有a对牛棚互相有仇恨,所以不能让他们的路连接到同一个中转站. 还有b对牛棚互相喜欢,所以他们的路必须连到同一个中专站.…
Building roads Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6229   Accepted: 2093 Description Farmer John's farm has N barns, and there are some cows that live in each barn. The cows like to drop around, so John wants to build some ro…
题目 //最小生成树,只是变成二维的了 #define _CRT_SECURE_NO_WARNINGS #include<stdlib.h> #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<math.h> using namespace std; #define inf 999999999 #define M 10…
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 (0 ≤ c ≤ 1). One Katu is solvable if one can find each vertex Vi a value Xi (0 ≤ Xi ≤ 1) s…
题意:给一棵树,在树中删除一些边,使得有一个连通块刚好为p个节点,问最少需要删除多少条边? 思路: 因为任一条边都可能需要被删除,独立出来的具有p个节点的连通块可能在任意一处地方.先从根开始DFS,然后进行树DP,dp[t][i]表示在以t为根的子树中删除i个点需要删除多少条边.dp[t][n-p]有可能是答案了,但是这种仅考虑到从树上脱落掉部分子树,那么留下的连通块通常是与1号点(树根)相连的,那如果所需要的连通块是在某棵子树中呢?将所有可能的子树取出来,若该子树节点数>=p,那么就可以在该子…
Problem Description Farmer John's farm has N barns, and there are some cows that live in each barn. The cows like to drop around, so John wants to build some roads to connect these barns. If he builds roads for every pair of different barns, then he…
题目链接 题意 : 给你一棵树,问你至少断掉几条边能够得到有p个点的子树. 思路 : dp[i][j]代表的是以i为根的子树有j个节点.dp[u][i] = dp[u][j]+dp[son][i-j]-1,son是u的儿子节点.初始是将所有的儿子都断开,然后-1代表的是这个儿子我需要了,不断了. #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define…
原题 2-SAT+二分答案! 最小的最大值,这肯定是二分答案.而我们要2-SATcheck是否在该情况下有可行解. 对于目前的答案limit,首先把爱和恨连边,然后我们n^2枚举每两个点通过判断距离来实现连边,然后跑2-SAT判断是否有可行解 O(n^2logn) 想起来和听起来都很难写,事实上还好吧- #include<cstdio> #include<algorithm> #include<stack> #include<cstring> #define…
把爱恨和最大距离视为限制条件,可以知道,最大距离和限制条件多少具有单调性 所以可以二分最大距离,加边+check #include<cstdio> #include<algorithm> #include<cstring> #include<vector> #include<stack> #define N 5010 #define INF 4000000 using namespace std; ],love[N][],indx,inst[N]…
POJ 2749 分解因数(计蒜客) Description 给出一个正整数a,要求分解成若干个正整数的乘积,即a = a1 * a2 * a3 * - * an,并且1 < a1 <= a2 <= a3 <= - <= an,问这样的分解的种数有多少.注意到a = a也是一种分解. Input 第1行是测试数据的组数n,后面跟着n行输入.每组测试数据占1行,包括一个正整数a (1 < a < 32768) Output n行,每行输出对应一个输入.输出应是一个正…