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

2011年4月24日

poj 2376

摘要: 贪心。代码:#include<iostream>#include<fstream>using namespace std;struct e{ int s,t;};e a[25001];int n;int cmp(const void *a,const void *b){ return (*(e *)a).s-(*(e *)b).s;}void read(){// ifstream cin("in.txt"); int i,j,k,s,t,T; cin>>n>>T; for(i=0;i<n;i++) cin>> 阅读全文

posted @ 2011-04-24 15:39 宇宙吾心 阅读(367) 评论(0) 推荐(0)

2011年4月23日

poj 2313

摘要: 贪心。代码:#include<iostream>#include<fstream>using namespace std;int b[101],a[101];int n;int cmp(const void *a,const void *b){ return *(int*)a-*(int*)b;}int solve(int n1,int n2,int n3){ int c[3]; c[0]=n1;c[1]=n2;c[2]=n3; qsort(c,3,sizeof(int),cmp); return c[1];}void read(){// ifstream cin(&q 阅读全文

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

poj 1907

摘要: 贪心。代码:#include<iostream>#include<fstream>using namespace std;int n,m,num;struct e{ char c[20]; int sum;};e a[101];int cmp(const void *a,const void *b){ e s,t; s=*(e*)a;t=*(e*)b; if(s.sum!=t.sum) return s.sum-t.sum; else return strcmp(s.c,t.c);}void read(){// ifstream cin("in.txt&quo 阅读全文

posted @ 2011-04-23 16:56 宇宙吾心 阅读(270) 评论(0) 推荐(0)

poj 1456

摘要: 贪心+并查集。代码:#include<iostream>#include<fstream>using namespace std;int n;struct e{ int s,t;};int cmp(const void *a,const void *b){ return (*(e *)b).s-(*(e *)a).s;}e p[10001];int f[10001];void init(){ int i; for(i=0;i<=10000;i++) { f[i]=i; }}int father(int s){ if(s!=f[s]) f[s]=father(f[s 阅读全文

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

poj 1230

摘要: 贪心。代码:#include<iostream>#include<fstream>using namespace std;int a[101][2];int b[101];int n,m;void read(){// ifstream cin("in.txt"); int i,j,k,s,t,maxx,ans,maxx1; cin>>k; while(k--) { cin>>n>>m; ans=0; maxx=0; for(i=1;i<=n;i++) { cin>>a[i][0]>>s 阅读全文

posted @ 2011-04-23 15:24 宇宙吾心 阅读(427) 评论(0) 推荐(0)

2011年4月22日

poj 2663

摘要: 关键是递推公式。代码:#include<iostream>#include<fstream>using namespace std;long long a[31];void read(){// ifstream cin("in.txt"); int i,j,k;a[0]=1; a[2]=3;a[4]=11; for(i=6;i<=30;i+=2) a[i]=4*a[i-2]-a[i-4]; while(cin>>i) { if(i==-1) return; if(i%2) cout<<0<<endl; els 阅读全文

posted @ 2011-04-22 16:10 宇宙吾心 阅读(412) 评论(0) 推荐(0)

poj 2229

摘要: 关键是递推公式。代码:#include<iostream>#include<fstream>using namespace std;long long a[1000001];void read(){// ifstream cin("in.txt"); int i,j,k; a[1]=1; a[2]=2; for(i=3;i<=1000000;i++) if(i%2) a[i]=a[i-1]; else { a[i]=a[i-2]+a[i/2]; a[i]%=1000000000; } cin>>i; cout<<a[i] 阅读全文

posted @ 2011-04-22 15:33 宇宙吾心 阅读(235) 评论(0) 推荐(0)

poj 1664

摘要: 递推公式。代码:#include<iostream>#include<fstream>using namespace std;int dp[11][11];int v[11][11];int solve(int s,int t){ if(t==0) return 1; if(s==1) return 1; if(v[s][t]) return dp[s][t]; v[s][t]=1; dp[s][t]=solve(s-1,t); if(t>=s) dp[s][t]+=solve(s,t-s); return dp[s][t];}void read(){// ifs 阅读全文

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

poj 1283

摘要: 关键是递推公式。代码:#include<iostream>#include<fstream>using namespace std;long long dp[201][201];void read(){// ifstream cin("in.txt"); int i,j,k,n,m; for(i=1;i<=200;i++) dp[i][i]=1; for(i=1;i<=200;i++) for(j=i+1;j<=200;j++) dp[i][j]=dp[i-1][j-1]+dp[i][j-i]; while(cin>>n 阅读全文

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

2011年4月19日

poj 1595

摘要: 水题代码:#include<iostream>#include<fstream>using namespace std;int a[1201],n;int b[1201],top;void prim(){ int i,j,k; if(n==1) { a[1]=1; top=1; return; } if(n==2) { a[1]=1; a[2]=2; top=2; return; } a[1]=1;a[2]=2; memset(b,0,sizeof(b)); top=2; for(i=2;i<=n;i+=2) b[i]=1; for(i=3;i<=n;i+= 阅读全文

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

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

导航