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

2011年4月19日

poj 1338

摘要: 注意理解算法。代码:#include<iostream>#include<fstream>using namespace std;long long a[1501];void read(){// ifstream cin("in.txt"); int i,j,k; int a1=1,a2=1,a3=1; a[1]=1; a1=1; a2=1; a3=1; for(i=2;i<=1500;i++) { a[i]=min(a[a1]*2,min(a[a2]*3,a[a3]*5)); if(a[i]==a[a1]*2) a1++; if(a[i]== 阅读全文

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

poj 1226

摘要: 水题。代码:#include<iostream>#include<string.h>#include<fstream>using namespace std;char x[101][101];char c[101];char str[101],str1[101];int len=101,n;void read(){// ifstream cin("in.txt"); int i,j,k,m,s,t; cin>>k; while(k--) { cin>>n; len=101; for(i=0;i<n;i++) 阅读全文

posted @ 2011-04-19 15:47 宇宙吾心 阅读(633) 评论(0) 推荐(0)

poj 1032

摘要: 假设最大积的分解为n=a1+a2+a3+...+a[t-2]+a[t-1]+a[t](a1<a2<a3<...<a[t-2]<a[t-1]<a[t])我们来证明这个数列的一些性质;1.1<a1if a1=1, then a1(=1), a[t] together could be replaced by a[t]+1.2.to all i, a[i+1]-a[i]<=2;if some i make a[i+1]-a[i]>=3,then a[i],a[i+1] together could be replaced by a[i]+1,a[ 阅读全文

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

poj 1091

摘要: 容斥原理。代码:#include<iostream>#include<fstream>using namespace std;long long n,m;long long num[60],cnt[60];long long top,per;long long f(long long ,long long);void get(long long s,long long t,long long p){ long long i; if(t==p) { long long j=m; for(i=0;i<t;i++) j/=cnt[i]; per+=f(j,n); } e 阅读全文

posted @ 2011-04-19 13:32 宇宙吾心 阅读(569) 评论(0) 推荐(0)

poj 2337

摘要: 欧拉路径。代码:#include<iostream>#include<fstream>#include<vector>#include<algorithm>using namespace std;int n;char x[1001][22];struct e{ int data; int num; int vis;};int in[30],out[30],v[30];vector<e> edge[30],edge1[30];int cmp1(const void *a,const void*b){ char *s1=(char *)a 阅读全文

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

2011年4月17日

poj 1386

摘要: 要判连通性,代码:#include<iostream>#include<fstream>#include<vector>using namespace std;int in[30];int out[30];int n;int v[30];vector<int> edge[27];void dfs(int s){ v[s]=1; for(int i=0;i<edge[s].size();i++) if(v[edge[s][i]]==0) dfs(edge[s][i]);}int ok(int s){ int i; memset(v,0,siz 阅读全文

posted @ 2011-04-17 19:38 宇宙吾心 阅读(384) 评论(0) 推荐(1)

poj 2369

摘要: 置换。代码:#include<iostream>#include<fstream>using namespace std;int a[1001];int n;int v[1001];int gcd(long long s,long long t){ if(t==0) return s; return gcd(t,s%t);}void read(){// ifstream cin("in.txt"); int i,j,k,s; cin>>n; long long ans=1; for(i=1;i<=n;i++) cin>> 阅读全文

posted @ 2011-04-17 19:03 宇宙吾心 阅读(297) 评论(0) 推荐(0)

poj 1041

摘要: 简单欧拉回路。代码:#include<iostream>#include<fstream>#include<vector>using namespace std;struct e{ int data; int num;};vector<e> a[51];int v[51];int vis[2000];void solve(int s){ for(int i=0;i<a[s].size();i++) { if(vis[a[s][i].num]==0) { vis[a[s][i].num]=1; solve(a[s][i].data); cou 阅读全文

posted @ 2011-04-17 18:30 宇宙吾心 阅读(560) 评论(0) 推荐(0)

2011年4月16日

poj 3670

摘要: 递增或递减序列。代码:#include<iostream>#include<fstream>using namespace std;int a[30001];int n;int b[30001];int c[30001];int find(int s,int value){ int i=0,k; while(i<=s) { k=(i+s)>>1; if(b[k]<value) s=k-1; else i=k+1; } return s;}int find1(int s,int value){ int i=0,k; while(i<=s) { 阅读全文

posted @ 2011-04-16 20:44 宇宙吾心 阅读(314) 评论(0) 推荐(0)

poj 1065

摘要: 偏序定理。同3636代码:#include<iostream>#include<fstream>using namespace std;struct e{ int w,h;};e a[5001];int n;int b[5001];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*)a)->h-((e*)b)->h;}int find(int s,int v 阅读全文

posted @ 2011-04-16 20:28 宇宙吾心 阅读(178) 评论(0) 推荐(0)

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

导航