首页 > 代码库 > 杭电OJ(HDU)-ACM Steps-Chapter Two-《Biker's Trip Odometer》《Climbing Worm》《hide handkerchief》《Nasty Hac》
杭电OJ(HDU)-ACM Steps-Chapter Two-《Biker's Trip Odometer》《Climbing Worm》《hide handkerchief》《Nasty Hac》
1.2.1 Biker's Trip Odometer #include<stdio.h> #include<math.h> const double PI=acos(-1.0); /* 计算题,根据公式做就行,PI*d*r/(12*5280);res1/t*3600; Sample Input 26 1000 5 27.25 873234 3000 26 0 1000 Sample Output Trip #1: 1.29 928.20 Trip #2: 1179.86 1415.84 */ int main() { double d; int r; double t; int iCase=0; while(scanf("%lf%d%lf",&d,&r,&t),r) { iCase++; double res1=PI*d*r/(12*5280); double res2=res1/t*3600; printf("Trip #%d: %.2lf %.2lf\n",iCase,res1,res2); } return 0; } 1.2.2 Climbing Worm #include<stdio.h> #include<math.h> /* Sample Input 10 2 1 20 3 1 0 0 0 总长为n,上升一秒走u,休息一秒下降d.相当于每两秒走(u-d);先n-u,得到过了多少个u-d后超过n-u; Sample Output 17 19 */ int main() { int n=1,u=1,d=1; while(scanf("%d %d %d",&n,&u,&d),n) { int t=(n-u)/(u-d); if(t*(u-d)<(n-u)) t++; t*=2; t++; printf("%d\n",t); } return 0; } 1.2.3 hide handkerchief #include<stdio.h> /* 丢手绢,用约瑟夫即可解决或者/辗转相除 3 2 -1 -1 */ int main() { int N,M,a; while(scanf("%d%d",&N,&M)==2) { if(N==-1&&M==-1) break; while(M!=0&&M!=1) { a=N%M; N=M; M=a; } printf("%s\n",M? "YES":"POOR Haha"); } return 0; } 1.2.4 Nasty Hacks #include<stdio.h> /* 题意:e-c 跟r比较。 3 0 100 70 100 130 30 -100 -70 40 */ int main() { int r,e,c; int t; while(scanf("%d",&t)!=EOF) { while(t--) { scanf("%d%d%d",&r,&e,&c); if(r>(e-c))printf("do not advertise\n"); else if(r<(e-c))printf("advertise\n"); else printf("does not matter\n"); } } return 0; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。