- 博客(39)
- 资源 (5)
- 收藏
- 关注
原创 poj2728 Desert King,最优比例生成树
题意:有n个村庄,村庄在不同坐标和海拔,现在要对所有村庄供水,只要两个村庄之间有一条路即可, 建造水管距离为坐标之间的欧几里德距离(好象是叫欧几里德距离吧),费用为海拔之差 现在要求方案使得费用与距离的比值最小很显然,这个题目是要求一棵最优比率生成树,0-1分数规划,0-1分数规划是分数规划的一种特殊情况,分数规划适用于求解最优化问题的,对于
2014-09-29 17:33:50 3114
原创 SPOJ104 Highways,生成树计数
高速公路(SPOJ104 Highways) 一个有n座城市的组成国家,城市1至n编号,其中一些城市之间可以修建高速公路。现在,需要有选择的修建一些高速公路,从而组成一个交通网络。你的任务是计算有多少种方案,使得任意两座城市之间恰好只有一条路径? 数据规模:1≤n≤12。 生成树计数算法步骤:1、 构建拉普拉斯矩阵 Matrix[i][j
2014-09-28 20:28:16 2418
原创 poj1639 Picnic Planning,K度限制生成树
题意:矮人虽小却喜欢乘坐巨大的轿车,车大到可以装下无论多少矮人。某天,N(N≤20)个矮人打算到野外聚餐。为了集中到聚餐地点,矮人A 要么开车到矮人B 家中,留下自己的轿车在矮人B 家,然后乘坐B 的轿车同行;要么直接开车到聚餐地点,并将车停放在聚餐地。虽然矮人的家很大,可以停放无数量轿车,但是聚餐地点却最多只能停放K 辆轿车。给你一张加权无向图,描述了N 个矮人的家和聚餐地点,求出所有矮人开
2014-09-28 19:56:37 2083
原创 poj1502 MPI Maelstrom,单源最短路的最长距离,dijkstra + 优先队列
点击打开链接求顶点1到其他点的最短距离的最长距离。。测试。。dijkstra + 优先队列#include #include #include #include #include #include #include #include #include #include #include #define for0(a,b) for
2014-09-26 14:53:21 1980
原创 poj3999 Kind of a Blur,高斯消元
Kind of a BlurTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 642 Accepted: 137DescriptionImage blurring occurs when the object being captured is out of
2014-09-26 11:35:44 2409
原创 poj3007 Organize Your Train part II, 字符串hash
题意:给定一个字符串,从任意位置把它切为两半,得到两条子串定义 子串1为s1,子串2为s2,子串1的反串为s3,子串2的反串为s4现在从s1 s2 s3 s4中任意取出两个串组合,问有多少种不同的组合方法#include #include #include #include #include #include #include #include #inc
2014-09-25 16:07:28 2227 2
原创 Ural 1416 Confidential,次小生成树
不严格次小生成树。注意图可能不连通。#include #include #include #include using namespace std;const int maxn = 505;const int INF = 1e7;bool vis[maxn];int d[maxn];int pre[maxn];int Max[maxn][maxn];
2014-09-23 23:15:16 2123
原创 hdu4268 Alice and Bob,multiset
Alice and BobProblem DescriptionAlice and Bob's game never ends. Today, they introduce a new game. In this game, both of them have N different rectangular cards respectively. Alice wants to us
2014-09-23 17:25:07 1901
原创 UVa11991 Easy Problem from Rujia Liu? map,vector
Easy Problem from Rujia Liu?Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 2006, Beijing 2007 and Wuhan 2009, or UVa OJ contests like Rujia L
2014-09-22 19:03:15 1679
原创 UVa156 Ananagrams,map
AnanagramsMost crosswordpuzzle fans are used to anagrams--groups of wordswith the same letters in different orders--for example OPTS, SPOT, STOP, POTSand POST. Some words however do not have this at
2014-09-22 18:46:45 1781
原创 hdu 4006 The kth great number,set,priority_queue
The kth great numberXiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the numb
2014-09-22 17:33:11 1796
原创 UVa10815,Andy's First Dictionary, set,stringstream
题意:输入一个文本,找出所有不同的单词,按字典序输出所有单词。stringstream通常是用来做数据转换的相比c库的转换,它更加安全,自动和直接#include stringstream streamstream stream >>value 读取#include #include #include #include #in
2014-09-22 16:52:33 1674
原创 hdu 2072 单词数,set,strtok
STL_set操作:st.begin()返回指向第一个元素额迭代器st.end()返回指向末尾元素的迭代器st.rbegin()返回逆向迭代器,指向链表末尾st.rend()返回指向开头之前位置的迭代器st.clear()清空迭代器
2014-09-22 16:33:55 1739
原创 poj1208 The Blocks Problem,模拟,vector
题意:从左到右有n个积木,依次编号0~n-1,要求模拟以下4种操作。1、move a onto ba和b都是积木的编号,先将a和b上面所有的积木都放回原处,再将a放在b上。2、move a over ba和b都是积木的编号,先将a上面所有的积木放回原处,再将a放在b上。(b上原有积木不动)3、pile a onto ba和b都是积木的编号,将a和其上面所有的积极
2014-09-22 16:04:37 1823
原创 UVa10474 Where is the Marble ? 有序数组二分找值,lower_bound / upper_bound
题意:给出n个数,先把各数从小到大排序,然后q次询问xi在数组中的位置,不存在则输出相应信息。输入样例:4 1235155 213331230 0输出样例:CASE# 1:5 found at 4CASE# 2:2 not found3 found at 3//=====
2014-09-22 14:23:10 1752
原创 poj 1679 The Unique MST,次小生成树
次小生成树求最小生成树时,用数组Max[i][j]来表示MST中i到j的最大边权。求完后,直接枚举所有不在MST中的边,替换掉最大边权的边,更新答案。#include #include #include using namespace std;const int maxn = 110;const int INF = 1e9;bool vis[maxn];in
2014-09-20 01:23:52 1977
转载 2-sat问题
序言 最近花了一点心思研究2-sat模型,看了很多论文博客等等,也在POJ上做了一点题。其实这个东西也还挺好玩的,当然,前提是每道题你都有认真分析,认真想清楚模型的意义,搞明白为什么可以这样,而不是简单的知道怎样做,就套上一个模板了事,那样,是不是也太糟蹋这门科学了。 关于2-sat,基本上所有人都会推荐两个资料: 伍昱 由对称性解
2014-09-19 16:18:42 1707
原创 hdu1814 Peaceful Commission,2-sat
题目大意:一国有n个党派,每个党派在议会中都有2个代表,现要组建和平委员会,要从每个党派在议会的代表中选出1人,一共n人组成和平委员会。已知有一些代表之间存在仇恨,也就是说他们不能同时被选为和平委员会的成员,现要你判断满足要求的和平委员会能否创立?如果能,请任意给出一种方案。2-sat问题#include #include #include #include #
2014-09-19 16:17:11 1962
原创 hdu2767 Proving Equivalences,有向图强联通,Kosaraju算法
点击打开链接有向图强联通,Kosaraju算法缩点后分别入度和出度为0的点的个数 answer = max(a, b);scc_cnt = 1; answer = 0#include#include#include#include#includeusing namespace std;const int maxn = 20000 + 1
2014-09-19 13:53:44 1652
原创 hdu3844 Mining Your Own Business,无向图的双连通分量
点击打开链接无向图的双连通分量#include#include#include#include#include#include#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;typedef long long LL;const int maxn = 50010;
2014-09-19 11:33:29 1743
原创 poj2942 Knights of the Round Table,无向图点双联通,二分图判定
点击打开链接无向图点双联通,二分图判定#include #include #include #include #include using namespace std;struct Edge{ int u, v;};const int maxn = 1005;int pre[maxn], iscut[maxn], bccno[maxn],dfs_c
2014-09-19 11:13:11 1805
原创 hdu1151 Air Raid,DAG图的最小路径覆盖
点击打开链接有向无环图的最小路径覆盖 = 顶点数- 最大匹配#include #include #include #include #include using namespace std;const int maxn = 150;int g[maxn][maxn];int n, m;int link[maxn];bool used[maxn];bool
2014-09-18 10:52:09 1583
原创 hdu1068 Girls and Boys,二分图最大独立集
点击打开链接二分图最大独立集 = 顶点数 - 最大匹配数#include #include #include #include #include using namespace std;const int maxn = 1005;int g[maxn][maxn];int n;int link[maxn];bool used[maxn];bool dfs(i
2014-09-18 10:39:28 1645
原创 [HAOI2005]路由选择问题,次短路
【问题描述】 X城有一个含有N个节点的通信网络,在通信中,我们往往关心信息从一个节点I传输到节点J的最短路径。遗憾的是,由于种种原因,线路中总有一些节点会出故障,因此在传输中要避开故障节点。任务一:在己知故障节点的情况下,求避开这些故障节点,从节点I到节点J的最短路径S0。任务二:在不考虑故障节点的情况下,求从节点I到节点J的最短路径S1、第二最短路径S2。【输入文件
2014-09-17 11:18:58 2045
原创 poj2449 Remmarguts' Date,第K短路
点击打开链接SPFA + A*#include #include #include #include using namespace std;struct node { int v, dis, f, next; friend bool operator <(node a, node b){ return a.f>b.f; }};const in
2014-09-16 23:12:44 1857
原创 POJ2186 Popular Cows ,有向图, Tarjan算法
题意:给定一个有向图,求有多少个顶点是由任何顶点出发都可达的。顶点数定理:有向无环图中唯一出度为0的点,一定可以由任何点出发均可达(由于无环,所以从任何点出发往前走,必然终止于一个出度为0的点)1. 求出所有强连通分量2. 每个强连通分量缩成一点,则形成一个有向无环图DAG。3. DAG上面如果有唯一的出度为0的点,则该点能被所有的点可达。那么该
2014-09-15 21:08:32 1746
原创 poj1041 John's trip,无向图求欧拉回路路径
点击打开链接无向图求欧拉回路:1、图连通2、所有顶点的度数位偶数#include #include #include #include #include using namespace std;const int mt = 2000;const int ms = 50;bool vis[mt+5];int g[ms][mt+5];
2014-09-15 19:52:29 1981
原创 UVa10054 The Necklace,无向图求欧拉回路
无向图求欧拉回路:1、图连通 2、所有顶点的度数位偶数随便从一个点开始递归遍历即可求出路径#include #include #include using namespace std;const int maxcolor = 50;int n, G[maxcolor+1][maxcolor+1], deg[maxcolor+1];str
2014-09-15 19:50:11 1729
原创 poj1201 Intervals,差分约束问题,spfa
题目大意:有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai,bi]这个区间的整数至少有ci个。如果存在这样的序列,请求出满足题目要求的最短的序列长度是多少。如果不存在则输出 -1。输入:第一行包括一个整数n,表示区间个数,以下n行每行描述这些区间,第i+1行三个整数ai,bi,ci,由空格隔开,其中0输出:一行,输出满足要求
2014-09-12 16:04:56 1809
原创 poj3311 Hie with the Pie,状态压缩
题目链接:http://poj.org/problem?id=3311Floyd + 状态压缩DP题意是有N个城市(1~N)和一个PIZZA店(0),要求一条回路,从0出发,又回到0,而且距离最小。状态:dp[S][v]表示从v出发访问剩余的所有顶点(集合S),最终回到顶点0的路径的权重总和最小值。#include #include #inc
2014-09-11 15:13:12 1739
原创 poj 3692 Kindergarten,二分图的最大团
最大独立集 = V - 最小顶点覆盖二分图的最小顶点覆盖数 = 最大匹配数最大团 = 补图的最大独立集#include #include #include #include #include #include using namespace std;const int maxn = 200 + 10;int n, m, s;int map[max
2014-09-11 11:15:45 1777
原创 poj1419 Graph Coloring,无向图,最大独立集
最大独立集 = 补图的最大团最小顶点覆盖 + 最大独立集 = V#include #include const int maxn =100 + 10;int g[maxn][maxn], dp[maxn], n;int x[maxn], ans[maxn], mx;int dfs(int *adj, int ns, int dep) { int t[maxn];
2014-09-11 10:49:39 2226
原创 UVA11324 The Largest Clique,有向图,最大团的结点数
点击打开链接有向图把强联通分量缩点后得到一个DAG,然后DP。#include #include #include #include #include #include using namespace std;const int maxn = 1000 + 10;vector G[maxn];int dfn[maxn], low[maxn], sccno
2014-09-11 10:31:35 2209
原创 hdu1530 Maximum Clique,最大团 , DP,邻接矩阵
Given a graph G(V, E), a clique is a sub-graph g(v, e), so that for all vertex pairs v1, v2 in v, there exists an edge (v1, v2) in e. Maximum clique is the clique that has maximum number of vertex.
2014-09-11 08:41:21 2142
原创 POJ 1149 PIGS ,最大流
大意:有M个猪圈,每个猪圈里初始时有若干头猪。一开始所有猪圈都是关闭的。依次来了N个顾客,每个顾客分别会打开指定的几个猪圈,从中买若干头猪。每个顾客分别都有他能够买的数量的上限。每个顾客走后,他打开的那些猪圈中的猪,都可以被任意地调换到其它开着的猪圈里,然后所有猪圈重新关上。问总共最多能卖出多少头猪。(1 构造这个网络模型的规则: • 每个顾客分别用一个结点来表示。 • 对
2014-09-06 02:42:11 1949
原创 ZOJ Monthly, June 2012 ,update~
zoj 3612 Median Vector + lower_bound能过~好像用其他数据结构也能过。我找来 Size Balanced Tree 板子试了一下也能很快得通过。 zoj 3616 Choir III注意题目给出的数据范围100行 2000列,行很少,所以可以考虑暴力枚举子矩阵的行数(起始行,和终止行),然后再从第一列开始枚举,直到某一列出现负数,就
2014-09-03 16:18:53 1597
原创 ZOJ Monthly, July 2012
zoj 3622、Magic Number 水题先找规律生成区间[1,1内的所有Magic Number,计算出来只有40多个,然后就随便YY了。void init(){ int a[5] = { 1,2,5,25,125 }; ll Max = (1ll<<32)-1; for(ll tmp =1; tmp<=Max; tmp *=10) { for(int
2014-09-03 11:24:54 1931
《Streaming Systems》 英文版 完整版
2018-10-11
hadoop-common-2.2.0-bin_32bit_&_64bit
2015-05-19
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人