标签:pac 个人 print 文件 stream a* iostream 编译器 如何
1 #include <stdio.h> 2 void test(int x[]) 3 { 4 int a = x[0]*1000 + x[1]*100 + x[2]*10 + x[3]; 5 int b = x[4]*10000 + x[5]*1000 + x[6]*100 + x[7]*10 + x[8]; 6 7 if(a*3==b) printf("%d / %d\n", a, b); 8 } 9 void f(int x[], int k) 10 { 11 int i,t; 12 if(k>=9){ 13 test(x); 14 return; 15 } 16 17 for(i=k; i<9; i++){ 18 {t=x[k]; x[k]=x[i]; x[i]=t;} 19 f(x,k+1); 20 _____________________________________________ // 填空处 21 } 22 } 23 24 int main() 25 { 26 int x[] = {1,2,3,4,5,6,7,8,9}; 27 f(x,0); 28 return 0; 29 }
结果:
1 #include <stdio.h> 2 3 void test(int x[]) 4 { 5 int a = x[0]*1000 + x[1]*100 + x[2]*10 + x[3]; 6 int b = x[4]*10000 + x[5]*1000 + x[6]*100 + x[7]*10 + x[8]; 7 8 if(a*3==b) printf("%d / %d\n", a, b); 9 } 10 11 void f(int x[], int k) 12 { 13 int i,t; 14 if(k>=9){ 15 test(x); 16 return; 17 } 18 19 for(i=k; i<9; i++){ 20 {t=x[k]; x[k]=x[i]; x[i]=t;} 21 f(x,k+1); 22 {t=x[k];x[k]=x[i];x[i]=t;}// 填空处 23 } 24 } 25 26 int main() 27 { 28 int x[] = {1,2,3,4,5,6,7,8,9}; 29 f(x,0); 30 return 0; 31 }
1 #include<stdio.h> 2 int main() 3 { 4 int sum=1225; 5 int tmp1,tmp2; 6 for(int i=1;i<47;i++) 7 { 8 tmp1=sum-(i+i+1)+(i*(i+1)); 9 for(int j=i+2;j<49;j++) 10 { 11 tmp2=tmp1-(j+j+1)+(j*(j+1)); 12 if(tmp2==2015) 13 printf("%d\n",i); 14 } 15 } 16 return 0; 17 }
16
项目三:牌型种数
1 #include <stdio.h> 2 typedef long long LL; 3 4 LL dp[14][14]; // dp[i][j]: 当前到第i张牌,总共有j张牌时的解的个数 5 6 int main() { 7 dp[1][0] = dp[1][1] = dp[1][2] = dp[1][3] = dp[1][4] = 1; 8 9 for (int i = 2; i <= 13; i++) { 10 for (int k = 0; k <= 13; k++) { 11 if (k - 4 >= 0) dp[i][k] += dp[i-1][k-4]; 12 if (k - 3 >= 0) dp[i][k] += dp[i-1][k-3]; 13 if (k - 2 >= 0) dp[i][k] += dp[i-1][k-2]; 14 if (k - 1 >= 0) dp[i][k] += dp[i-1][k-1]; 15 dp[i][k] += dp[i-1][k]; 16 } 17 } 18 19 printf("%d",dp[13][13]); 20 return 0; 21 }
35981800
项目四:移动距离
1 #include <iostream> 2 3 #include <math.h> 4 5 using namespace std; 6 7 int main() 8 9 { 10 11 int w, m, n; 12 13 int i, j, k = 1; 14 15 int mi, mj, ni, nj; 16 17 cin >> w >> m >> n; 18 19 int arr[1001][w]; 20 21 for (i = 0; i<1001; i++) 22 23 { 24 25 if ((i + 1) % 2 != 0) 26 27 { 28 29 for (j = 0; j<w; j++) 30 31 { 32 33 arr[i][j] = k + j; 34 35 } 36 37 k = arr[i][j - 1]; 38 39 } 40 41 else{ 42 43 int f = 1; 44 45 for (j = w - 1; j >= 0; j--, f++) 46 47 { 48 49 arr[i][j] = k + f; 50 51 } 52 53 k = arr[i][0] + 1; 54 55 } 56 57 } 58 59 for (i = 0; i<1001; i++) 60 61 { 62 63 for (j = 0; j<w; j++) 64 65 { 66 67 if (arr[i][j] == n) 68 69 { 70 71 ni = i; 72 73 nj = j; 74 75 } 76 77 if (arr[i][j] == m) 78 79 { 80 81 mi = i; 82 83 mj = j; 84 85 } 86 87 } 88 89 } 90 91 int a = abs(mi - ni); 92 93 int b = abs(mj - nj); 94 95 printf("%d\n",a+b); 96 97 return 0; 98 99 }
标签:pac 个人 print 文件 stream a* iostream 编译器 如何
原文地址:https://www.cnblogs.com/liugangjiayou/p/10585222.html