第 21 题 (5 分)
有 6 个城市,任何两个城市之间都有一条道路连接,6 个城市两两之间的距离如下表所示,则城市 1 到城市 6 的最短距离为____。
第 22 题 (5 分)
书架上有 21 本书,编号从 1 到 21,从其中选 4 本,其中每两本的编号都不相邻的选法一共有____种。
第 23 题 (8 分)
1 #include<iostream> 2 using namespace std; 3 int main() { 4 int i, a, b, c, d, f[4]; 5 for(i = 0; i < 4; i++) cin >> f[i]; 6 a = f[0] + f[1] + f[2] + f[3]; 7 a = a / f[0]; 8 b = f[0] + f[2] + f[3]; 9 b = b / a; 10 c = (b * f[1] + a) / f[2]; 11 d = f[(b / c ) % 4]; 12 if(f[(a + b + c + d) % 4] > f[2]) 13 cout << a + b<< endl; 14 else cout << c + d << endl; 15 return 0; 16 }
输入:
9 19 29 39
输出:____
第 24 题 (8 分)
1 #include<iostream> 2 using namespace std; 3 void foo(int a, int b, int c) { 4 if (a > b) 5 foo(c, a, b); 6 else 7 cout << a << ',' << b << ',' << c << endl; 8 } 9 int main() { 10 int a, b, c; 11 cin >> a >> b >> c; 12 foo(a, b, c); 13 return 0; 14 }
输入:
1
3 1 2
输出:
____
第 25 题 (8 分)
1 #include<iostream> 2 using namespace std; 3 void f(int a, int b, int c) { 4 cout << a << b << c << ‘/’; 5 if(a == 3 && b == 2 && c == 1) 6 return; 7 if(b < c) 8 f(a, c, b); 9 else if(a < b) { 10 if(a < c) 11 f(c, a, b); 12 else 13 f(b, c, a); 14 } 15 } 16 int main() { 17 int a, b, c; 18 cin >> a >> b >> c; 19 f(a, b, c); 20 cout << endl; 21 return 0; 22 }
输入:
1
1 3 2
输出:____
第 26 题 (8 分)
1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 int i,j,len; 5 char s[50]; 6 int main() { 7 cin >>s; 8 len = strlen(s); 9 for (i = 0; i < len; ++i) { 10 if (s[i] >= 'A' && s[i] <= 'Z') s[i] -= 'A' - 'a'; 11 } 12 for (i = 0; i < len; ++i) { 13 if (s[i] < 'x') s[i] += 3; 14 else s[i] += -23; 15 } 16 cout <<s<<'/'; 17 for (j = 1; j < 4; j++) { 18 for (i = 0; i < len-j; i = i + j) { 19 s[i] = s[i + j] ; 20 } 21 } 22 cout <<s<< endl; 23 return 0; 24 }
输入:
1
ABCDEFGuvwxyz
输出:____
第 27 题
(找第 k 大的数)给定一个长度为 1,000,000 的无序正整数序列, 以及另一个数 n (1\le n\le10000001≤n≤1000000), 然后以类似快速排序的方法找到序列中第 n 大的数(关于第 n 大的数:例如序列 {1,2,3,4,5,6} 中第 3 大的数是 4)。
1 #include <iostream> 2 using namespace std; 3 int a[1000001],n,ans = -1; 4 void swap(int &a,int &b) { 5 int c; 6 c = a; 7 a = b; 8 b = c; 9 } 10 int FindKth(int left, int right, int n) { 11 int tmp,value,i,j; 12 if (left == right) return left; 13 tmp = rand()% (right - left) + left; 14 swap(a[tmp],a[left]); 15 value = ① 16 i = left; 17 j = right; 18 while (i < j) { 19 while (i < j &&②) j --; 20 if (i < j) { 21 a[i] = a[j]; 22 i++; 23 } else break; 24 while (i < j &&③) i++; 25 if (i < j) { 26 a[j] = a[i]; 27 j - -; 28 } else break; 29 } 30 ④ 31 if (i < n) return FindKth( ⑤); 32 if (i > n) return ⑥ 33 return i; 34 35 } 36 37 int main() { 38 int i; 39 int m = 1000000; 40 for (i = 1; i <= m; i++) 41 cin >> a[i]; 42 cin >> n; 43 ans = FindKth(1,m,n); 44 cout << a[ans]; 45 return 0; 46 }
填空位置 ①(3 分):
填空位置 ②(3 分):
填空位置 ③(3 分):
填空位置 ④(3 分):
填空位置 ⑤(3 分):
填空位置 ⑥(3 分):
第 28 题
(矩阵中的数字)有一个 n×n(1≤n≤5000)的矩阵 a,对于 1<i < n,1<j<n,a[i][j]<a[i+1][j]、a[j][i]<a[j][i+1]。即矩阵中左右相邻的两个元素,右边的元素一定比左边的大。上下相邻的两个元素,下面的元素一定比上面的大。给定矩阵 a 中的一个数字 k,找出 k 所在的行列(注意:输入数据保证矩阵中的数各不相同)。
1 #include <iostream> 2 using namespace std; 3 int n,k,answerx,answery; 4 int a[5001][5001]; 5 void FindKPosition() { 6 7 int i = n,j = n; 8 9 while (j > 0) { 10 if(a[n][j] < k) break; 11 j --; 12 } 13 ① 14 while (a[i][j] != k) { 15 while (② && i > 1) i --; 16 while (③ && j <= n) j++; 17 } 18 ④ 19 ⑤ 20 } 21 int main() { 22 int i, j; 23 cin >> n; 24 for (i = 1; i <= n; i++) 25 for (j = 1; j <= n; j++) 26 cin >> a[i][j]; 27 cin >> k; 28 FindKPosition(); 29 cout << answerx << "" << answery << endl; 30 return 0; 31 }
填空位置 ①(2 分):
填空位置 ②(2 分):
填空位置 ③(2 分):
填空位置 ④(3 分):
填空位置 ⑤(2 分):
参考答案: