0 of 2 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 2 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
一、(大整数除法)给定两个正整数 p 和 q,其中 p 不超过 \(10^{100}\), q 不超过 100000, 求 p 除以 q 的商和余数。
输入:第一行是 p 的位数 n,第二行是正整数 p,第三行是正整数 q。
输出:两行,分别是 p 除以 q 的商和余数。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#include <iostream> using namespace std; int p[100]; int n, i, q, rest; char c; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> c; p[i] = c - '0'; } cin >> q; rest = (1); i = 1; while ((2) && i < n) { rest = rest * 10 + p[i]; i++; } if (rest < q) cout << 0 << endl; else { cout << (3); while (i < n) { rest = (4); i++; cout << rest / q; } cout << endl; } cout << (5) << endl; return 0; } |
填空一: , 填空二: , 填空三: 填空四: 填空五:
二、(最长路径)给定一个有向无环图,每条边长度为1,求图中的最长路径长度。
输入:第一行是结点数 n (不超过 100)和边数 m,接下来 m 行,每行两个整数 a,b,表示从结点 a 到结点 b 有一条有向边。结点标号从 0 到 (n−1)。 输出: 最长路径长度。
提示:先进行拓扑排序,然后按照拓扑序计算最长路径。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
#include <iostream> using namespace std; int n, m, i, j, a, b, head, tail, ans; int graph[100][100]; // 用邻接矩阵存储图 int degree[100]; // 记录每个结点的入度 int len[100]; // 记录以各结点为终点的最长路径长度 int queue[100]; // 存放拓扑排序结果 int main() { cin >> n >> m; for (i = 0; i < n; i++) for (j = 0; j < n; j++) graph[i][j] = 0; for (i = 0; i < n; i++) degree[i] = 0; for (i = 0; i < m; i++) { cin >> a >> b; graph[a][b] = 1; (1); } tail = 0; for (i = 0; i < n; i++) if ((2)) { queue[tail] = i; tail++; } head = 0; while (tail < n - 1) { for (i = 0; i < n; i++) if (graph[queue[head]][i] == 1) { (3); if (degree[i] == 0) { queue[tail] = i; tail++; } } (4); } ans = 0; for (i = 0; i < n; i++) { a = queue[i]; len[a] = 1; for (j = 0; j < n; j++) if (graph[j][a] == 1 && len[j] + 1 > len[a]) len[a] = len[j] + 1; if ((5)) ans = len[a]; } cout << ans << endl; return 0; } |
填空一:
填空二:
填空三:
填空四:
填空五: