上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 57 下一页

2011年7月22日

poj 2253 Frogger

摘要: #include <iostream> //prime算法的变形,求一条路径,使得它的最大边达到最小值#include<cmath>using namespace std;int loc[205][2],edge[205][205],n,t,i,j,k;const int MaxWeight=3000000;struct Mintree { int end,weight; //没有必要记录起点}mintree[205],e;void Prim(){ int min,v,com; for(i=0;i<n-1;++i) //求n-1条边 { min=MaxWeight 阅读全文

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

poj 1942 Paths on a Grid

摘要: #include<iostream> //组合数using namespace std;int main(){ long long m,n,i,j,res; while(scanf("%lld%lld",&n,&m)&&(n||m)) { if(n>m) swap(n,m); res=1,j=2; for(i=m+1;i<=m+n;++i) { res*=i; while(j<=n&&res%j==0) { res/=j; j++; } } printf("%lld\n",re 阅读全文

posted @ 2011-07-22 16:31 sysu_mjc 阅读(103) 评论(0) 推荐(0) 编辑

poj 2029 Get Many Persimmon Trees

摘要: #include <iostream> //树状数组using namespace std;int n,w,h,x,y,s,t,max_val,table[105][105];int lowbit(int x){ return x&(-x);}void modify(int x,int y){ while(x<100) { int j=y; while(j<100) { table[x][j]++; j+=lowbit(j); } x+=lowbit(x); }}int sum(int x,int y){ int s=0; while(x>0) { int 阅读全文

posted @ 2011-07-22 16:31 sysu_mjc 阅读(125) 评论(0) 推荐(0) 编辑

poj 1797 Heavy Transportation

摘要: #include <iostream> //dijstra算法的变形,求一条路径,使得它的最小边达到最大值#include<set>using namespace std;int t,n,m,i,j,v,harsh[1005],edge[1005][1005],distD[1005],visit[1005];void Dijstra() { visit[1]=1;distD[1]=0; for(i=2;i<=v;++i) { distD[i]=edge[1][harsh[i]]; visit[i]=0; } for(i=2;i<=v;++i) { int M 阅读全文

posted @ 2011-07-22 16:30 sysu_mjc 阅读(124) 评论(0) 推荐(0) 编辑

poj 1861 Network

摘要: #include <iostream> //kruskalusing namespace std;const int max_ve=1005,max_ed=15005;int n,m,i,flag[max_ed]; //n,m分别记录顶点数和边数struct node{ int par;}vertex[max_ve];struct Edge { int u,v,weigh;}edge[max_ed];int cmp(const void* a,const void* b){ return (*(Edge*)a).weigh-(*(Edge*)b).weigh;}int find_p 阅读全文

posted @ 2011-07-22 16:30 sysu_mjc 阅读(125) 评论(0) 推荐(0) 编辑

poj 1604 Just the Facts

摘要: #include <iostream> //计算 n!的最后一位非零位,时间复杂度为0(logn)#include <cmath> using namespace std; int fac[10];int get2(int n) { if(n==0) return 0; return n/2+get2(n/2);}int get5(int n) { if(n==0) return 0; return n/5+get5(n/5);}int g(int n,int x){ if(n... 阅读全文

posted @ 2011-07-22 16:29 sysu_mjc 阅读(144) 评论(0) 推荐(0) 编辑

poj 1458 Common Subsequence

摘要: // 题意:求两个字符串的最长公共子序列#include<iostream> //最长公共子序列#include<string>using namespace std;string str1,str2;int f[500][500];int lcs(int i,int j){ if(i==-1||j==-1) return 0; if(f[i][j]!=-1) return f[i][j]; else if(str1[i]==str2[j]) f[i][j]=lcs(i-1,j-1)+1; else ... 阅读全文

posted @ 2011-07-22 16:28 sysu_mjc 阅读(103) 评论(0) 推荐(0) 编辑

poj 1204 Word Puzzles

摘要: /* 题意: 给定一个L*C的单词表,给定W个单词,查找每个单词匹配的起始坐标位置,题目保证有解 可以沿着8个方向进行查找: A 代表正北,顺时针依次是 B(东北),C(正东),... 思路: 如果将单词表建 trie 树,这样数据规模会太大, 所以要对查找的单词建 trie 树,然后将单词表拿到 trie 数组中搜索, 枚举单词表的每个位置作为匹配的起始位置,再枚举8个方向进行查找, 如果能从根节点搜索到叶节点,说明该叶节点表示的这个单词存在,也就找到该单词匹配的起始坐标位置和方向 要是中途遇到为空的trie节点,则表示没有单词与之匹配,就不必要再继续往下查找了*/#include < 阅读全文

posted @ 2011-07-22 16:21 sysu_mjc 阅读(128) 评论(0) 推荐(0) 编辑

poj 1195 Mobile phones

摘要: // 题意: n*n的矩阵 ,定义两种操作:// (1) x y a : [x,y]的值加上a (2) x1 y1 x2 y2 : 查询子矩阵[x1,y1] -[x2,y2]的和#include <iostream> //简单二维树状数组using namespace std;int C[1025][1025]; //树状数组初始化为0int side;int lowbit(int x){ return x&(-x);}void modify(int x,int y,int a){ x++;y++; //让数组下标从 1 开始 wh... 阅读全文

posted @ 2011-07-22 16:15 sysu_mjc 阅读(119) 评论(0) 推荐(0) 编辑

poj 1200 Crazy Search

摘要: #include <iostream> //hash#include <string>using namespace std;bool table[20000000];int ans[100],count,curr; //注意有大小写字母char ch[1000000]; //本题中的输入字符串ch相当大,另外,table也要开得很大int main(){ int n,nc,len; memset(ans,-1,sizeof(ans)); scanf("%d%d%s",&n,&nc,ch); len=strlen(ch); for(i 阅读全文

posted @ 2011-07-22 16:15 sysu_mjc 阅读(179) 评论(0) 推荐(0) 编辑

上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 57 下一页

导航