2011年5月9日

poj 2823

摘要: 单调队列的经典题代码:#include<iostream>#include<fstream>#include<queue>using namespace std;#define MAX 1000000int a[1000001];int minn[1000001];int maxx[1000001];int n,m,f1,r1,f2,r2;void read(){// ifstream cin("in.txt"); int i,j,k; scanf("%d%d",&n,&m); for(i=1;i< 阅读全文

posted @ 2011-05-09 19:47 宇宙吾心 阅读(299) 评论(0) 推荐(0)

poj 1733

摘要: 并查集代码:#include<iostream>#include<fstream>#include<vector>using namespace std;int f[10001];int d[10001];struct e{ int s,t;};vector<e> a[9950];int n,m;void init(){ int i,j,k; for(i=1;i<=10000;i++) { f[i]=i; }}int find(int s){ int i,j,k; s=s%9949; if(a[s].size()==0) { e b; b. 阅读全文

posted @ 2011-05-09 18:54 宇宙吾心 阅读(283) 评论(0) 推荐(0)

poj 3250

摘要: 同3494代码:#include<iostream>#include<fstream>using namespace std;long long a[80010];int lef[80010];int n;void read(){// ifstream cin("in.txt"); int i,j,k; cin>>n; for(i=1;i<=n;i++) cin>>a[n-i+1]; a[0]=a[n+1]=2000000000; for(i=1;i<=n;i++) lef[i]=i; for(i=1;i<= 阅读全文

posted @ 2011-05-09 16:26 宇宙吾心 阅读(255) 评论(0) 推荐(0)

poj 2796

摘要: 同3494代码:#include<iostream>#include<fstream>using namespace std;long long a[100011],lef[100011],rig[100011];long long n;void read(){// ifstream cin("in.txt"); long long i,j,k; scanf("%lld",&n); for(i=1;i<=n;i++) scanf("%lld",&a[i]); for(i=1;i<=n 阅读全文

posted @ 2011-05-09 16:06 宇宙吾心 阅读(397) 评论(0) 推荐(0)

poj 3494

摘要: 一类连续最大区域问题代码:#include<stdio.h>#include<fstream>int a[2001][2001];int n,m;int h[2001][2001];int left[2001],right[2001];int max(int s,int t){ if(s<t) return t; else return s;}void read(){// ifstream cin("in.txt"); int i,j,k; while(scanf("%d%d",&n,&m)!=EOF){ f 阅读全文

posted @ 2011-05-09 15:51 宇宙吾心 阅读(368) 评论(0) 推荐(0)

poj 1686

摘要: 判断两个表达式是否相同。代码:#include<iostream>#include<fstream>#include<stack>using namespace std;char c1[2000],c2[2000];char s1[2000],s2[2000],s[2000];int a[126];int ok(char c){ if(c>='0'&&c<='9') return 1; if(c>='a'&&c<='z') return 1 阅读全文

posted @ 2011-05-09 14:51 宇宙吾心 阅读(397) 评论(0) 推荐(0)

poj 3253

摘要: 题目就是给一块木板,它有一个长度,现在要把它据成一个个指定长度的木板,但每次锯一块木板的时候要收取木板长度那么多钱。现在给定小木板的个数,以及每个小木板的长度,问从一个全长为所有木板和的木板锯成这些小木板,需要交的最少金额是多少。算法:这题其实就是让你构造哈夫曼树,这样的代价是最小的。但我们不必真的去构造哈夫曼树,我们只需要了解我们在树中要得到的东西就行了。在这题中我们需要从哈夫曼树的最底层的子树根结点值开始加起,每次只加根结点的值,一直走到总根结点就行,也就是说,每次取最小的两个数相加。可以用优先队列实现。代码:#include<iostream>#include<fstr 阅读全文

posted @ 2011-05-09 12:05 宇宙吾心 阅读(193) 评论(0) 推荐(0)

poj 2247

摘要: 经典题,注意输出代码:#include<iostream>#include<fstream>using namespace std;long long a[5843];long long min(long long s,long long t){ if(s<t) return s; return t;}void read(){// ifstream cin("in.txt"); int i,j,k; int n1,n2,n3,n4; n1=1;n2=1;n3=1;n4=1; a[1]=1; for(i=2;i<=5842;i++) { a 阅读全文

posted @ 2011-05-09 11:32 宇宙吾心 阅读(332) 评论(0) 推荐(0)

导航