afterward

导航

 

2012年8月2日

摘要: #include <iostream>#include <iomanip>using namespace std;int main(){ int n=12; double s,avg=0; while(n--){ cin>>s;avg=avg+s;} avg=avg/12;// cout<<"$"<<avg<<endl; printf("%.2f",avg); //setprecision只有在设置了fixed或者scientific的时候才表示有效小数位数, //否则表示域宽 co 阅读全文
posted @ 2012-08-02 21:03 afterward 阅读(388) 评论(0) 推荐(0) 编辑
 
摘要: View Code #include <iostream>#include <algorithm>using namespace std;class DNA{public:char DNAString[51];int length;int measure;DNA(){ length=0; measure=0;}DNA(const DNA &a ){ length=a.length; measure=a.measure; for (int i=0;i<length;++i ) DNAString[i]=a.DNAString[i]; DNAString[le 阅读全文
posted @ 2012-08-02 20:49 afterward 阅读(113) 评论(0) 推荐(0) 编辑
 
摘要: 最简单的贪心算法;先排序,后一次找出单价最小的一次加入;不够的加入剩下的前初一单价得到的质量。View Code #include <iostream>#include<algorithm>#include<iomanip>#include <string.h>#include<stdio.h>using namespace std;struct mi{ int s; int t;};bool cmp(mi a,mi b){ return a.s<b.s;//单价从小到大排列}int main(){ double w; int 阅读全文
posted @ 2012-08-02 20:32 afterward 阅读(230) 评论(0) 推荐(0) 编辑
 
摘要: 辗转相除法,代码比较简单记一下。View Code #include<stdio.h>void main(){ int a,b,c,t; while(scanf("%d %d",&a,&b) != EOF){ if (a<b){ t=a;a=b;b=t; } c=a; while(c%b!=0) c+=a; printf("%d\n",c); }} 阅读全文
posted @ 2012-08-02 20:11 afterward 阅读(124) 评论(0) 推荐(0) 编辑
 

2012年8月1日

摘要: 先将田忌和国王的马都排序。若田忌赢了n场,用田忌的前n个赢一定是最优的。View Code #include<iostream>#include <algorithm>using namespace std;bool cmp(int x,int y){ return x>y;}int main(){ int x,n,i,j,k; n=0; int a[1005],b[1005];//a 田忌 ; b 国王; int s; while( cin>>x&&x) { for(i=0;i<x;i++) cin>>a[i]; s 阅读全文
posted @ 2012-08-01 22:10 afterward 阅读(535) 评论(0) 推荐(0) 编辑
 
摘要: 这个跟上次做的Flower很像,但我最先想到的是贪心。变形的找多个范围的含这个数的范围有多少个。把每条竖着的走廊看做一个单位,占用的次数记录,找出最大值。想不到这点真的很难做啊。View Code #include<stdio.h>#include<string.h>int main(){ int i,j,n,t,p,q,max,tmp; int a[205]; scanf("%d",&t); while(t--) { scanf("%d",&n); memset(a,0,size... 阅读全文
posted @ 2012-08-01 11:18 afterward 阅读(242) 评论(0) 推荐(0) 编辑
 
摘要: 先展示一个我同学些的代码,超级goodView Code #include<iostream>#include<cstdio>#include<cstring>using namespace std;int C[150005];int B[150005];//int Out[150005];int N=150005;int Lowbit(int x){ return x&(-x);}void Modify(int i,int x){ while(i>0) { cout<<i<<" : "<< 阅读全文
posted @ 2012-08-01 09:34 afterward 阅读(359) 评论(1) 推荐(0) 编辑
 

2012年7月30日

摘要: 这种想法最简单也可以实现#include<iostream>#include<string>using namespace std;int main(){ int p,e,i,d; int t=0; while(cin>>p>>e>>i>>d){t++; int k; if(p==-1&&i==-1&&e==-1&&d==-1) break; for(k=d+1;k<=21252;k++) if((k-p)%23==0)break; for(;k<=21252;k 阅读全文
posted @ 2012-07-30 20:13 afterward 阅读(139) 评论(0) 推荐(0) 编辑
 
摘要: View Code #include <iostream>using namespace std;int main(){ int n; int a[100],b[100],i,j,k,m; while(cin>>n&&n) { for(i=0;i<n;i++) cin>>a[i]>>b[i]; for(i=0;i<n;i++)//sort for(j=i+1;j<n;j++) if(b[i]>b[j]) { m=b[j];b[j]=b[i];b[i]=m; ... 阅读全文
posted @ 2012-07-30 10:40 afterward 阅读(990) 评论(0) 推荐(0) 编辑
 

2012年7月29日

摘要: View Code /*Sample Input3olleh !dlrowm'I morf .udhI ekil .mca Sample Outputhello world!I'm from hdu.I like acm.HintRemember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it. */#include<iostream>using namespace std;int mai 阅读全文
posted @ 2012-07-29 23:02 afterward 阅读(298) 评论(0) 推荐(0) 编辑