万卷网 > 题目详情
题型:简答题

(大整数除法)给定两个正整数p和q,其中p不超过10100,q不超过100000,

求p除以q的商和余数。(第一空2分,其余3分)

输入:第一行是p的位数n,第二行是正整数p,第三行是正整数q。

输出:两行,分别是p除以q的商和余数。


#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;

}

更新时间:2023-09-01 10:11:24 |
【知识点】 信息学NOIP提高组

相似题推荐

填空题

如下图所示,A到B是连通的。假设删除一条细的边的代价是1,删除一条粗的边的代价是2,要让A、B不连通,最小代价是_____(2分),最小代价的不同方案数是_______(3分)。(只要有一条删除的边不同,就是不同的方案)

2023-09-02
单选题

中国计算机学会于( )年创办全国青少年计算机程序设计竞赛。(2018年提高组)

A.

1983

B.

1984

C.

1985

D.

1986

2023-09-02
填空题

如右图所示,共有13个格子。对任何一个格子进行一次操作,会使得它自己以及与它上下左右相邻的格子中的数字改变(由1变0,或由0变1)。现在要使得所有的格子中的数字都变为0,至少需要      次操作。

2023-09-02
简答题

(最长路径)给定一个有向无环图,每条边长度为1,求图中的最长路径长度。(第五空2分,其余3分)

输入:第一行是结点数n(不超过100)和边数m,接下来m行,每行两个整数a,b,表示从结点a到结点b有一条有向边。结点标号从0到(n-1)。

输出:最长路径长度。

提示:先进行拓扑排序,然后按照拓扑序计算最长路径。


#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;

}

2023-09-02
单选题

设A和B是两个长为n的有序数组,现在需要将A和B合并成一个排好序的数组,请问任何以元素比较作为基本运算的归并算法最坏情况下至少要做( )次比较。

A.

n2

B.

n logn

C.

2n

D.

2n-1

2023-09-02
公众号
客服 反馈
顶部