- 博客(19)
- 收藏
- 关注
原创 [回溯]Mapping the Swaps UVA331
回溯求不同交换排序有多少种。 Mapping the Swaps Sorting an array can be done by swapping certain pairs of adjacent entries in the array. This is the fundamental technique used in the well-known bu
2013-11-16 20:23:40 1211
原创 [枚举]Getting in Line UVA 216
Getting in Line Computer networking requires that the computers in the network be linked.This problem considers a ``linear" network in which the computers are chained together so tha
2013-11-14 10:11:09 1027
原创 [枚举]The Psychic Poker Player UVA131
The Psychic Poker Player In 5-card draw poker, a player is dealt a hand of five cards (which may be looked at). The player may then discard between zero and five of his or her cards and
2013-11-12 07:49:19 1597
原创 The Hamming Distance Problem UVA729
给出两个数,一个是总位数,另一个是1的位数,求全排列#include#include#includeusing namespace std;int main(){ int n,k; cin>>n; for(k=1;k<=n;k++) { int r,t,i,j; cin>>r>>t; string
2013-11-10 14:38:04 931
原创 Generating Fast UVA10098
和上一道题差不多,调用STL#include#include#includeusing namespace std;bool cmp(char ch1,char ch2){ return ch1<ch2;}int main(){ int n; cin>>n; while(n--) { string str;
2013-11-10 10:48:48 1059 1
原创 ID Codes UVA 146
这道题的一开始题意都没看懂,后来才发现就是求一个序列按照字典序的下一个排列组合。。。可以直接调用STL#include #include #include using namespace std;int main(){ string str; while(cin >> str) { if(str[0]=='#') break;
2013-11-09 16:41:22 895
原创 XYZZY UVA10557
这道题用到了一个独特的算法SPFA,同时需要判断是否存在正环,刚开始的无从下手,后来参考别人的代码,就看明白了。#include#include#includeusing namespace std;#define maxn 110int grid[maxn][maxn],val[maxn][maxn],num[maxn][maxn];int vis[maxn],dis[
2013-11-05 21:29:53 844
原创 可以处理负权的单源最短路径的SPFA算法带图详解(自己画的图)
算法大致流程是用一个队列来进行维护。 初始时将源加入队列。 每次从队列中取出一个元素,并对所有与他相邻的点进行松弛,若某个相邻的点松弛成功,则将其入队。 直到队列为空时算法结束。这个算法,简单的说就是队列优化的bellman-ford,利用了每个点不会更新次数太多的特点发明的此算法SPFA——Shortest Path Faster Algorithm,它可以在O(kE)的时间复杂度内
2013-11-05 19:15:13 2070 2
原创 并查集算法
最近在图论这一块总遇到判断连通问题,判断图是否连通,可以用两种简单的方法(我目前知道的)—并查集和DFS,其中并查集可能更好理解,并查集的思路:并查集可以分为两个过程一个是归并过程一个是查找过程,其中在一个图中,一开始声明一个bin数组把所有的结点都指向结点自己本身,也就是bin[i]=i;i代表结点的序号,之后每次遇到一条连通的道路,比如a-b首先需要把a和b指向的根的结点找出来(当然一开始的时
2013-11-05 15:31:18 1177 2
原创 The Necklace UVA10054
又是一道无向图的欧拉图问题,首先判定是不是欧拉图,再输出,这里用到了一个算法:Fleury算法: (1)任取v0∈V(G),令P0=v0; (2)设Pi=v0e1v1e2...eivi已经行遍,按下面方法来从E(G)-{e1,e2,...,ei}中选 取ei+1: (a)ei+1与vi想关联; (b)除非无别的
2013-11-03 20:16:55 776
原创 Play on Words UVA10129
又是一道可以建模成欧拉图的问题,看题目第一感觉就是搜索或者递归,但是没有想到建模成欧拉图,对欧拉的图的判断还是太不清楚了,要多练练。#include#include#includeusing namespace std;int tag,m;int in[30],out[30];int grid[30][30],vis[30][30];void dfs(int k){
2013-11-03 10:22:20 737
原创 Morning Walk UVA 10596
这道题一看觉得是挺简单的欧拉图问题,一想总觉得不对劲,果然卡了很久,对欧拉图一点都不熟悉,代码还参考了别人的,在这里写一下欧拉图的判断有向图欧拉路或欧拉回路的判定方法:(1)有向图G为欧拉图(存在欧拉回路),当且仅当G的基图连通,且所有顶点的入度等于出度。(2)有向图G为半欧拉图(存在欧拉道路),当且仅当G的基图连通,且存在顶点u的入度比出度大1、v的入度比出度小1,其它所有顶点的入度
2013-11-02 14:59:44 850
原创 Bicoloring UVA 10004
有两种颜色,给一个无向图染色,要求相邻的点颜色不同。直接dfs。。这道题比较简单,但是我卡了很久。#include#includeusing namespace std;int grid[210][210];int color[210];int vis[210];int tag,n,m;void dfs(int pos){ int k; for(k=0
2013-11-01 22:13:48 601
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人