随笔分类 -  贪心

hdu 3348
摘要:当时想到了贪心,但没深想。注意贪心的方向。 阅读全文

posted @ 2011-08-15 19:42 宇宙吾心 阅读(184) 评论(0) 推荐(0)

poj 1862
摘要:贪心#include<iostream>#include<fstream>#include<cmath>#include<queue>using namespace std;int n;void read(){// ifstream cin("in.txt"); int i,j,k; double s,t; cin>>n; priority_queue<double> q; for(i=1;i<=n;i++) { cin>>j; t=j; q.push(t); } while(1) { 阅读全文

posted @ 2011-06-15 15:50 宇宙吾心 阅读(187) 评论(0) 推荐(0)

poj 3298
摘要:贪心代码:#include<iostream>#include<fstream>using namespace std;int a[30001];int n;void read(){// ifstream cin("in.txt"); int i,j,k; int cas; cin>>cas; while(cas--) { cin>>n; for(i=1;i<=n;i++) cin>>a[i]; j=1;k=a[1];i=2; int ans=1; while(i<=n) { if(k<a[i]& 阅读全文

posted @ 2011-05-06 17:31 宇宙吾心 阅读(167) 评论(0) 推荐(0)

poj 3069
摘要:贪心代码:#include<iostream>#include<fstream>using namespace std;int a[1001];int n,m;int cmp(const void *a,const void *b){ return *(int*)a-*(int*)b;}void read(){// ifstream cin("in.txt"); int i,j,k; while(cin>>m>>n) { if(m==-1&&n==-1) return; for(i=0;i<n;i++) 阅读全文

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

poj 3085
摘要:水题。代码:#include<iostream>#include<fstream>using namespace std;void read(){// ifstream cin("in.txt"); int i,j,k; int n1,n2,n3,n4; cin>>k; for(i=1;i<=k;i++) { cin>>j; n1=j/25; j%=25; n2=j/10; j%=10; n3=j/5; j%=5; n4=j; printf("%d %d QUARTER(S), %d DIME(S), %d N 阅读全文

posted @ 2011-04-25 15:49 宇宙吾心 阅读(244) 评论(0) 推荐(0)

poj 2726
摘要:贪心代码:#include<iostream>#include<fstream>using namespace std;struct e{ int s,t;};e a[10001];int n;int cmp(const void *a,const void *b){ e *s=(e*)a; e *t=(e*)b; if(s->s!=t->s) return s->s-t->s; else return s->t-t->t;}void read(){// ifstream cin("in.txt"); int i, 阅读全文

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

poj 2586
摘要:贪心。代码:#include<iostream>#include<fstream>using namespace std;void read(){// ifstream cin("in.txt"); int i,j,k,s,t; while(cin>>s>>t) { t=-t; if(s*4+t<0) { if(10*s+2*t>0) cout<<10*s+2*t<<endl; else cout<<"Deficit"<<endl; } else 阅读全文

posted @ 2011-04-25 15:10 宇宙吾心 阅读(157) 评论(0) 推荐(0)

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

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

poj 2431
摘要:贪心代码:#include<iostream>#include<fstream>#include<queue>using namespace std;int n;typedef struct e{ int s,t; bool friend operator <(const e &a,const e &b){ return a.t<b.t; }}e;e a[10001];int cmp(const void *a,const void *b){ return (*(e*)a).s-(*(e*)b).s;}priority_queue 阅读全文

posted @ 2011-04-24 16:53 宇宙吾心 阅读(267) 评论(0) 推荐(0)

poj 2393
摘要:贪心。代码:#include<iostream>#include<fstream>using namespace std;long long n;void read(){// ifstream cin("in.txt"); long long i,j,k,s,t,minn; long long ans=0; cin>>n>>k; cin>>s>>t; ans=s*t; minn=s; for(i=1;i<n;i++) { cin>>s>>t; minn=min(minn+k 阅读全文

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

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)

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 宇宙吾心 阅读(273) 评论(0) 推荐(0)

导航