2064 汉诺塔III
1 #include<stdio.h> 2 3 int main(){ 4 int n,i; 5 _int64 s[40]; 6 while(~scanf("%d",&n)){ 7 s[1] = 2; 8 for(i=2;i<=n;i++){ 9 s[i] = 3*s[i-1] + 2; 10 } 11 printf("%I64d ",s[n]); 12 } 13 14 }
2067 小兔的棋盘
1 #include<stdio.h> 2 3 4 int main(){ 5 int n,i,k,j=0; 6 _int64 s[40] = {0}; 7 s[1] = 1;s[0] = 1; 8 for(i=2;i<=35;i++){ 9 for(k=0;k<i;k++){ 10 s[i] += s[k]*s[i-1-k]; 11 } 12 } 13 while(~scanf("%d",&n)){ 14 if(n==-1){break;} 15 16 printf("%d %d %I64d ",++j,n,s[n]*2); 17 } 18 19 }
卡特兰数的推导公式:
2068 RPG的错排
1 #include<stdio.h> 2 _int64 c(int a,int b){ 3 _int64 mul1=1,mul2=1,i; 4 for(i=a;i>0;i--){ 5 mul1 *= i; 6 mul2 *= b; 7 b--; 8 } 9 return mul2/mul1; 10 } 11 12 int main(){ 13 int n,i; 14 _int64 s[15],sum; 15 s[1] = 0;s[2] = 1; 16 for(i=3;i<15;i++){ 17 s[i] = (i-1)*(s[i-1]+s[i-2]); 18 } 19 while(~scanf("%d",&n)){ 20 if(n==0){break;} 21 sum = 1; 22 for(i=1;i<=n/2;i++){ 23 sum += c(i,n)*s[i]; 24 } 25 printf("%I64d ",sum); 26 27 } 28 29 }
2073 无限的路
1 #include<stdio.h> 2 #include<math.h> 3 double len(int x,int y){ 4 int i,j; 5 double len = 0,l; 6 double t = sqrt(2); 7 for(i=1;i<x+y;i++){ 8 len = len + t*i; 9 } 10 for(i=0;i<x+y;i++){ 11 len = len + sqrt(i*i+(i+1)*(i+1)); 12 } 13 len = len + t*x; 14 return len; 15 } 16 17 int main(){ 18 int n,x1,y1,x2,y2; 19 while(~scanf("%d",&n)){ 20 while(n--){ 21 scanf("%d %d %d %d",&x1,&y1,&x2,&y2); 22 23 printf("%.3lf ",fabs(len(x2,y2)-len(x1,y1))); 24 } 25 } 26 27 }
2076 夹角有多大(题目已修改,注意读题)
1 #include<stdio.h> 2 #include<math.h> 3 4 int main(){ 5 int n; 6 double h,m,s,anh,anm,an; 7 while(~scanf("%d",&n)){ 8 while(n--){ 9 scanf("%lf %lf %lf",&h,&m,&s); 10 if(h>11){h = h-12;} 11 anh = (h+(m+s/60)/60)*30; 12 anm = (m+s/60)*6; 13 an = fabs(anh - anm); 14 if(an>180){an = 360 -an;} 15 printf("%d ",(int)an); 16 } 17 } 18 19 }
2077 汉诺塔IV
1 #include<stdio.h> 2 #include<math.h> 3 4 int main(){ 5 int n,i,m; 6 _int64 s[21]; 7 s[0] = 0; 8 s[1] = 1; 9 for(i=2;i<21;i++){ 10 s[i] = s[i-1]*3 + 1; 11 } 12 while(~scanf("%d",&n)){ 13 while(n--){ 14 scanf("%d",&m); 15 printf("%I64d ",s[m-1]*2+2); 16 } 17 } 18 19 }
2078 复习时间
1 #include<stdio.h> 2 #include<math.h> 3 4 int main(){ 5 int t,n,m,s[45],i,j,temp,min; 6 while(~scanf("%d",&t)){ 7 while(t--){ 8 scanf("%d %d",&n,&m); 9 for(i=1;i<=n;i++){ 10 scanf("%d",&s[i]); 11 } 12 for(i=1;i<=n;i++){ 13 for(j=i+1;j<=n;j++){ 14 if(s[i]<s[j]){ 15 temp = s[i]; 16 s[i] = s[j]; 17 s[j] = temp; 18 } 19 } 20 } 21 22 printf("%d ",(100-s[n])*(100-s[n])); 23 } 24 } 25 }
2080 夹角有多大II
1 #include<stdio.h> 2 #include<math.h> 3 #define PI 3.1415926 4 5 int main(){ 6 int n; 7 double x1,x2,y1,y2,m,t; 8 while(~scanf("%d",&n)){ 9 while(n--){ 10 scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2); 11 m = x1*x2 + y1*y2; 12 t = sqrt((x1*x1+y1*y1)*(x2*x2+y2*y2)); 13 printf("%.2lf ",acos(m/t)/PI*180); 14 } 15 } 16 }
抄公式就完事了
2083 简易版之最短距离
1 #include<stdio.h> 2 #include<math.h> 3 4 int main(){ 5 int n,m,i,j,s[501],temp,d; 6 while(~scanf("%d",&n)){ 7 while(n--){ 8 scanf("%d",&m); 9 for(i=0;i<m;i++){ 10 scanf("%d",&s[i]); 11 } 12 for(i=0;i<m;i++){ 13 for(j=i;j<m;j++){ 14 if(s[i]>s[j]){ 15 temp = s[i]; 16 s[i] = s[j]; 17 s[j] = temp; 18 } 19 } 20 } 21 d = 0; 22 for(i=0;i<m;i++){ 23 d += abs(s[i] - s[m/2]); 24 } 25 printf("%d ",d); 26 } 27 } 28 }
2084 数塔
1 #include<stdio.h> 2 int max(int a,int b){ 3 if(a>b){return a;} 4 else{return b;} 5 } 6 7 int main(){ 8 int s[101][101]; 9 int dp[101][101]; 10 int c,n,i,j; 11 while(~scanf("%d",&c)){ 12 while(c--){ 13 scanf("%d",&n); 14 for(i=1;i<=n;i++){ 15 for(j=1;j<=i;j++){ 16 scanf("%d",&s[i][j]); 17 } 18 } 19 for(i=n;i>0;i--){ 20 for(j=1;j<=i;j++){ 21 if(i==n){ 22 dp[i][j] = s[i][j]; 23 }else{ 24 dp[i][j] = max(s[i][j]+dp[i+1][j],s[i][j]+dp[i+1][j+1]); 25 } 26 } 27 } 28 printf("%d ",dp[1][1]); 29 } 30 } 31 }
2085 核反应堆
1 #include<stdio.h> 2 3 int main(){ 4 int n,i; 5 _int64 h[35],l[35]; 6 h[0] = 1;l[0]=0; 7 while(~scanf("%d",&n)){ 8 if(n==-1){break;} 9 for(i=1;i<=n;i++){ 10 h[i] = h[i-1]*3 + l[i-1]*2; 11 l[i] = h[i-1] + l[i-1]; 12 } 13 printf("%I64d, %I64d ",h[n],l[n]); 14 } 15 16 }