上一页 1 ··· 22 23 24 25 26 27 28 29 30 ··· 36 下一页

2011年4月16日

poj 3636

摘要: 偏序定理。注意1. 偏序定理。2. 最长递减子序列的nlogn算法。3.qosrt是不稳定排序。代码:#include<iostream>#include<fstream>using namespace std;struct e{ int w,h;};e a[20001];int n;int b[20001];int cmp(const void *a,const void *b){ if(((e *)b)->w-((e*)a)->w!=0) return ((e *)a)->w-((e*)b)->w; else return ((e*)b)-& 阅读全文

posted @ 2011-04-16 19:48 宇宙吾心 阅读(393) 评论(0) 推荐(0)

poj 2533

摘要: 水题。o(n^2)也可以。代码:#include<iostream>#include<fstream>using namespace std;int a[10001];int b[10001];int n;void read(){// ifstream cin("in.txt"); int i,j,k; cin>>n; for(i=1;i<=n;i++) cin>>a[i]; for(i=1;i<=n;i++) b[i]=1; for(i=1;i<=n;i++) for(j=i-1;j>=0;j--) 阅读全文

posted @ 2011-04-16 18:19 宇宙吾心 阅读(212) 评论(0) 推荐(0)

2011年4月12日

poj 2429

摘要: 令x=lcm/gcd将x分解质因数->Pollard rho方法枚举将x分解为两个互素的数相乘代码:#include<ctime>#include<iostream>#include<fstream>using namespace std;long long factor[1000],fac_top = -1;//计算两个数的gcdlong long gcd(long long a,long long b){ if(a==0) return b; long long c; while(b!=0) { c=b; b=a%b; a=c; } return 阅读全文

posted @ 2011-04-12 18:33 宇宙吾心 阅读(1302) 评论(0) 推荐(0)

poj 2689

摘要: 两次筛选。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;long long a[47001];long long b[47001];long long c[1000001];int mark[1000001];void read(){// ifstream cin("in.txt"); long long i,j,k,top=0,top2; long long s,t,n1,n2,n3,n4; b[0]=2; for(i=4;i<=4 阅读全文

posted @ 2011-04-12 16:47 宇宙吾心 阅读(326) 评论(0) 推荐(1)

poj 1811

摘要: 模板题。代码:#include<ctime>#include<iostream>using namespace std;long long factor[100],fac_top = -1;//计算两个数的gcdlong long gcd(long long a,long long b){ if(a==0) return b; long long c; while(b!=0) { c=b; b=a%b; a=c; } return a;}//ret = (a*b)%n (n<2^62)long long muti_mod(long long a,long long 阅读全文

posted @ 2011-04-12 16:01 宇宙吾心 阅读(676) 评论(1) 推荐(0)

2011年4月11日

poj 3128

摘要: 置换分数幂性质。代码:#include<iostream>#include<fstream>using namespace std;void read(){// ifstream cin("in.txt"); int i,j,k,s; cin>>k; char c[30]; int num[30]; int v[30]; while(k--){ cin>>c; memset(v,0,sizeof(v)); memset(num,0,sizeof(num)); for(i=0;i<26;i++) if(v[i]==0) { 阅读全文

posted @ 2011-04-11 18:56 宇宙吾心 阅读(294) 评论(0) 推荐(0)

poj 1721

摘要: 置换。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;int a[41];int b[1001];int c[1001];int d[1001];int n;void read(){// ifstream cin("in.txt"); int i,j,k,ans,m,num,s; for(i=4;i<=40;i+=2) a[i]=1; for(i=3;i<=40;i+=2) if(a[i]==0) for(j=i*2;j<= 阅读全文

posted @ 2011-04-11 16:48 宇宙吾心 阅读(400) 评论(0) 推荐(0)

poj 3270

摘要: 注意离散化。代码:#include<iostream>#include<fstream>using namespace std;int n;int a[10001];int v[10001];int b[10001];int c[1000001];int cmp(const void *a,const void *b){ return *(int *)a-*(int *)b;}void read(){// ifstream cin("in.txt"); int i,j,k=100001,ans=0,sum,minn,s,num; scanf(&quo 阅读全文

posted @ 2011-04-11 14:04 宇宙吾心 阅读(179) 评论(0) 推荐(0)

2011年4月6日

poj 3258

摘要: 参数搜索。代码:#include<iostream>#include<fstream>using namespace std;long long n,m,l,mid;long long a[50001];int cmp(const void *a,const void *b){ return *(long long*)a-*(long long *)b;}int solve(){ int i,j=0,k=0; for(i=1;i<=n;i++) { if(a[i]-a[k]<mid) { j++; } else { k=i; } } if(l-a[k]< 阅读全文

posted @ 2011-04-06 18:37 宇宙吾心 阅读(233) 评论(0) 推荐(0)

poj 3273

摘要: 参数搜索。代码:#include<iostream>#include<fstream>using namespace std;long long n,m,mid;long long a[100001];long long solve(){ long long i,j=1,k=0; for(i=1;i<=n;i++) { if(a[i]-a[k]>mid) { j++; k=i-1; } } return j;}void read(){// ifstream cin("in.txt"); long long i,j,k=0,s; while 阅读全文

posted @ 2011-04-06 16:37 宇宙吾心 阅读(225) 评论(0) 推荐(0)

上一页 1 ··· 22 23 24 25 26 27 28 29 30 ··· 36 下一页

导航