刘汝佳算法入门之第二章之习题之三

摘要: #define LOCAL#include<stdio.h>int main(){ #ifdef LOCAL freopen("E:\\c\\input1.txt","r",stdin); freopen("E:\\c\\output.txt","w",stdout); #endif int x,y,z,i,j=0; while(scanf("%d%d%d",&x,&y,&z)==3) { for(i=10;i<=100;i++) { if(i%3==x 阅读全文
posted @ 2011-10-11 10:30 csushin 阅读(125) 评论(0) 推荐(0)

刘汝佳算法入门之第二章之习题之一

摘要: #define LOCAL#include<stdio.h>#include<math.h>int main(){ #ifdef LOCAL freopen("E:\\c\\input1.txt","r",stdin); freopen("E:\\c\\output1.txt","w",stdout); #endif int x0,x,i,n=0,count=1; while(scanf("%d",&x)==1) { x0=x; for(i=8;i>0;i- 阅读全文
posted @ 2011-10-10 23:50 csushin 阅读(144) 评论(0) 推荐(0)

刘汝佳算法入门之第二章之数理统计(fopen版)

摘要: #include<stdio.h>#define INF 1000000000int main(){ FILE *fin,*fout; fin=fopen("E:input.txt","rb"); fout=fopen("E:output.txt","wb"); int x,n=0,min=INF,max=-INF,s=0; while(fscanf(fin,"%d",&x)==1) { s+=x; if(x<min) min=x; if(x>max) max=x 阅读全文
posted @ 2011-10-10 00:30 csushin 阅读(154) 评论(0) 推荐(0)

刘汝佳算法入门之第二章之数理统计(重新定向版)

摘要: #define LOCAL//只有定义了这个才用#ifdef 和#endif中的语句#include<stdio.h>#define INF 1000000000int main(){ #ifdef LOCAL freopen("E:input.txt","r",stdin);//注意,第一项是落实写入路径,且在竞赛的时候需遵从题设,沿用体重规定文件名以及拓展名 freopen("E:output.txt","w",stdout); #endif int x,n=0,min=INF,max=-INF,s 阅读全文
posted @ 2011-10-10 00:29 csushin 阅读(136) 评论(0) 推荐(0)

刘汝佳算法入门之第二章之阶乘之和(2)

摘要: #include<stdio.h>#include<time.h>int main(){ const int MOD=1000000; int i,j,n,s=0; int factorial=1; scanf("%d",&n); if(n>25) n=25; for(i=1;i<=n;i++) { /*for(j=1;j<=i;j++) factorial*=j;*/ factorial=(factorial*=i)%MOD; s=(s+=factorial)%MOD; } printf("%d\n", 阅读全文
posted @ 2011-10-09 23:23 csushin 阅读(166) 评论(0) 推荐(0)

刘汝佳算法入门之第二章之阶乘之和(1)

摘要: #include<stdio.h>int main(){ int i,j,n,s=0; int factorial=1; scanf("%d",&n); for(i=1;i<=n;i++) { /*for(j=1;j<=i;j++) factorial*=j;*/ factorial*=i;//此处经过修改更加简便,少了一个for循环 s+=factorial; } printf("%d\n",s%1000000); return 0;}疑问,如果仍溢出,使用double型,但是double型数据似乎不能进行求余%的运算啊 阅读全文
posted @ 2011-10-09 23:06 csushin 阅读(216) 评论(0) 推荐(0)

刘汝佳算法入门之第二章之3N+1问题

摘要: #include<stdio.h>int main(){ int n,count=0; scanf("%d",&n); while(n>1) { if(n%2==1) {n=n*3+1;count++;n/=2;count++;} if(n%2==0) {n/=2;count++;}//与书中的进行了部分修改,防止溢出。 } printf("%d\n",count); return 0;} 阅读全文
posted @ 2011-10-09 22:50 csushin 阅读(148) 评论(0) 推荐(0)

刘汝佳算法入门之第一章之三整数排序

摘要: #include<stdio.h>int main(){ int a,b,c,x,y,z; scanf("%d%d%d",&a,&b,&c); x=a;if(b<x) x=b;if(c<x) x=c;//得到最大值 z=a;if(b>z) z=b;if(c>z) z=c;//得到最小值 y=a+b+c-x-z;//得到中间值 printf("%d %d %d\n",x,y,z); return 0;} 阅读全文
posted @ 2011-10-09 21:53 csushin 阅读(128) 评论(0) 推荐(0)

Section2.4

摘要: #include<stdio.h>int main(){ int N=12,i; float a,s=0; for(i=0;i<N;i++) { scanf("%f",&a); s=s+a; } printf("$%.2f\n",s/12);} 阅读全文
posted @ 2011-09-30 23:08 csushin 阅读(97) 评论(0) 推荐(0)

Section2.3

摘要: #include<stdio.h>int main(){ int i,u,n,d,t=0; while(scanf("%d%d%d",&n,&u,&d)!=EOF) { if(n==0&&u==0&&d==0) break; for(i=0;n-(u-d)*i>u;i++) { t=t+2; } t=t+1; printf("%d\n",t); t=0; }} 阅读全文
posted @ 2011-09-30 23:07 csushin 阅读(80) 评论(0) 推荐(0)