上一页 1 ··· 40 41 42 43 44 45 46 47 48 ··· 57 下一页

2011年7月17日

poj 1002 487-3279

摘要: #include <iostream>#include<string>#include<map>using namespace std;char mapping(char ch){ if(ch=='A'||ch=='B'||ch=='C')ch='2'; else if(ch=='D'||ch=='E'||ch=='F')ch='3'; else if(ch=='G'||ch=='H'||ch==&# 阅读全文

posted @ 2011-07-17 23:30 sysu_mjc 阅读(115) 评论(0) 推荐(0) 编辑

poj 1001 Exponentiation

摘要: // 题意:大数求幂 ,输入实数R,整数n,求R^n#include <iostream>#include <string>using namespace std;int compare(string str1, string str2){ while(!str1.empty()&&str1[0]=='0') { str1.erase(0,1); } while(!str2.empty()&&str2[0]=='0') { str2.erase(0,1); } if(str1.size() > str 阅读全文

posted @ 2011-07-17 23:28 sysu_mjc 阅读(155) 评论(0) 推荐(0) 编辑

转载:匈牙利算法求二分图的最大匹配

摘要: 用匈牙利算法求二分图的最大匹配什么是二分图,什么是二分图的最大匹配,这些定义我就不讲了,网上随便都找得到。二分图的最大匹配有两种求法,第 一种是最大流(我在此假设读者已有网络流的知识);第二种就是我现在要讲的匈牙利算法。这个算法说白了就是最大流的算法,但是它跟据二分图匹配这个问题的 特点,把最大流算法做了简化,提高了效率。匈牙利算法其实很简单,但是网上搜不到什么说得清楚的文章。所以我决定要写一下。最大流算法的核心问题就是找增广路径(augment path)。匈牙利算法也不例外,它的基本模式就是:初始时最大匹配为空while 找得到增广路径 do 把增广路径加入到最大匹配中去可见和最大流算法是 阅读全文

posted @ 2011-07-17 22:32 sysu_mjc 阅读(110) 评论(0) 推荐(0) 编辑

next_permutation函数

摘要: 这是一个求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm>下面是以前的笔记(1) int 类型的next_permutationint main(){ int a[3]; a[0]=1;a[1]=2;a[2]=3; do { cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl; } while (next_permutation(a,a+3)); //参数3指的是要进行排列的长度//如果存在a之后的排列,就返回tru 阅读全文

posted @ 2011-07-17 20:48 sysu_mjc 阅读(307) 评论(0) 推荐(0) 编辑

全排列

摘要: #include<iostream> //全排列的生成算法:字典序法,允许可重集#include<algorithm>using namespace std;int num[10]={0,4,3,1,9,10},n;void permutation(){ int i,j,k; sort(num+1,num+n+1); while(1) { for(i=1;i<=n;++i) cout<<num[i]<<" "; cout<<endl; for(i=n-1;i>=1;--i) if(num[i]<n 阅读全文

posted @ 2011-07-17 20:37 sysu_mjc 阅读(232) 评论(0) 推荐(0) 编辑

sicily 1889. Max’s game

摘要: // 题意: 有n*m矩阵,从起点(sx,sy)出发,可以上下左右四个方向移动,// 若两个位置上是相同字符,则花费为0,否则为1,求到终点的最短距离// 用Dijkstra算法解决,但会 TLE ,需要用 优先队列 优化时间#include <iostream> // 邻接矩阵+优先队列实现Dijkstra算法#include <stdio.h>#include <queue>#include <cstring>using namespace std; const int INF=300000;const int ... 阅读全文

posted @ 2011-07-17 14:49 sysu_mjc 阅读(210) 评论(1) 推荐(0) 编辑

sicily 1299. Academy Awards

摘要: #include<iostream>#include<string>#include<map>using namespace std;struct film{ int id,time;};int main(){ int n,m; string str,ss; while(cin>>n,n) { map<string,film> col; int id=1; while(n--) { cin>>ss>>m; while(m--) { cin>>str; if(col.find(str)!=col.en 阅读全文

posted @ 2011-07-17 12:06 sysu_mjc 阅读(207) 评论(0) 推荐(0) 编辑

sicily 1252. Defining Moment

摘要: #include<iostream> //字符串模拟题#include<string>using namespace std;string str;int st,ed;bool fit(int i,int j,string ss){ if(i<st||j>ed) return false; for(int k=0;k<=j-i;++k) if(str[k+i]!=ss[k]) return false; return true;}int main(){ int cases; cin>>cases; while(cases--) { stri 阅读全文

posted @ 2011-07-17 11:40 sysu_mjc 阅读(157) 评论(0) 推荐(0) 编辑

线段树之六

摘要: #include <iostream> //poj 2777 Count Color 线段树+位运算using namespace std;struct node{ int l,r,color; //采用位运算代替用一个vis[]数组来表示哪些颜色存在或不存在,这样既省空间也省时间}tree[300000];int c,count;void build(int s,int t,int num){ tree[num].l=s;tree[num].r=t; tree[num].color=1; if(s!=t) { int mid=(s+t)/2; build(s,mid,num*2) 阅读全文

posted @ 2011-07-17 02:02 sysu_mjc 阅读(160) 评论(0) 推荐(0) 编辑

线段树之五

摘要: #include <iostream> //poj 3368 Frequent values using namespace std;struct segment { int l,r,freq;}tree[400005];int arr[100005],group[100005][2],curr,attach[100005];void built_group(int n){ curr=1; group[curr][0]=group[curr][1]=1; attach[curr]=1; for(int i=2;i<=n;++i) { if(arr[i]==arr[i-1]) 阅读全文

posted @ 2011-07-17 02:01 sysu_mjc 阅读(108) 评论(0) 推荐(0) 编辑

上一页 1 ··· 40 41 42 43 44 45 46 47 48 ··· 57 下一页

导航