全部知识点
(矩形计数)平面上有n个关键点,求有多少个四条边都和x轴或者y轴平行的矩形,满足四个顶点都是关键点。给出的关键点可能有重复,但完全重合的矩形只计一次。
试补全枚举算法。
#include <stdio. h>
struct point {
int x, y, id;
};
int equals(struct point a, struct point b) {
return a.x == b.x && a.y == b.y;
}
int cmp(struct point a, struct point b) {
return ①;
}
void sort(struct point A[], int n) {
for (int i = 0; i < n; i++)
for (int j = 1; j < n; j++)
if (cmp(A[j], A[j - 1])) {
struct point t = A[j];
A[j] = A[j - 1];
A[j - 1] = t;
}
}
int unique(struct point A[], int n) {
int t = 0;
for(int i = 0; i < n; i++)
if (②)
A[t++] = A[i];
return t;
}
int binary_search(struct point А[], int n, int x, int y) {
struct point p;
p.x = x;
р.y = y;
p.id = n;
int a = 0,b = n - 1;
while (a < b) {
int mid = ③;
if (④)
a = mid + 1;
else
b = mid;
}
return equals(A[a], р);
}
#define MAXN 1000
struct point A[MAXN];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &A[i].x, &A[i].y);
A[i].id = i;
}
sort(A, n);
n = unique(A, n);
int ans = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (⑤ && binary_search(A, n, A[i].x, A[j].y) && binary_search(A, n, A[j].x, A[i].y)) {
ans++;
}
printf("%d\n", ans);
return 0;
}①处应填( )
(矩形计数)平面上有n个关键点,求有多少个四条边都和x轴或者y轴平行的矩形,满足四个顶点都是关键点。给出的关键点可能有重复,但完全重合的矩形只计一次。
试补全枚举算法。
#include <stdio. h>
struct point {
int x, y, id;
};
int equals(struct point a, struct point b) {
return a.x == b.x && a.y == b.y;
}
int cmp(struct point a, struct point b) {
return ①;
}
void sort(struct point A[], int n) {
for (int i = 0; i < n; i++)
for (int j = 1; j < n; j++)
if (cmp(A[j], A[j - 1])) {
struct point t = A[j];
A[j] = A[j - 1];
A[j - 1] = t;
}
}
int unique(struct point A[], int n) {
int t = 0;
for(int i = 0; i < n; i++)
if (②)
A[t++] = A[i];
return t;
}
int binary_search(struct point А[], int n, int x, int y) {
struct point p;
p.x = x;
р.y = y;
p.id = n;
int a = 0,b = n - 1;
while (a < b) {
int mid = ③;
if (④)
a = mid + 1;
else
b = mid;
}
return equals(A[a], р);
}
#define MAXN 1000
struct point A[MAXN];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &A[i].x, &A[i].y);
A[i].id = i;
}
sort(A, n);
n = unique(A, n);
int ans = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (⑤ && binary_search(A, n, A[i].x, A[j].y) && binary_search(A, n, A[j].x, A[i].y)) {
ans++;
}
printf("%d\n", ans);
return 0;
}②处应填( )
(矩形计数)平面上有n个关键点,求有多少个四条边都和x轴或者y轴平行的矩形,满足四个顶点都是关键点。给出的关键点可能有重复,但完全重合的矩形只计一次。
试补全枚举算法。
#include <stdio. h>
struct point {
int x, y, id;
};
int equals(struct point a, struct point b) {
return a.x == b.x && a.y == b.y;
}
int cmp(struct point a, struct point b) {
return ①;
}
void sort(struct point A[], int n) {
for (int i = 0; i < n; i++)
for (int j = 1; j < n; j++)
if (cmp(A[j], A[j - 1])) {
struct point t = A[j];
A[j] = A[j - 1];
A[j - 1] = t;
}
}
int unique(struct point A[], int n) {
int t = 0;
for(int i = 0; i < n; i++)
if (②)
A[t++] = A[i];
return t;
}
int binary_search(struct point А[], int n, int x, int y) {
struct point p;
p.x = x;
р.y = y;
p.id = n;
int a = 0,b = n - 1;
while (a < b) {
int mid = ③;
if (④)
a = mid + 1;
else
b = mid;
}
return equals(A[a], р);
}
#define MAXN 1000
struct point A[MAXN];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &A[i].x, &A[i].y);
A[i].id = i;
}
sort(A, n);
n = unique(A, n);
int ans = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (⑤ && binary_search(A, n, A[i].x, A[j].y) && binary_search(A, n, A[j].x, A[i].y)) {
ans++;
}
printf("%d\n", ans);
return 0;
}③处应填( )
(矩形计数)平面上有n个关键点,求有多少个四条边都和x轴或者y轴平行的矩形,满足四个顶点都是关键点。给出的关键点可能有重复,但完全重合的矩形只计一次。
试补全枚举算法。
#include <stdio. h>
struct point {
int x, y, id;
};
int equals(struct point a, struct point b) {
return a.x == b.x && a.y == b.y;
}
int cmp(struct point a, struct point b) {
return ①;
}
void sort(struct point A[], int n) {
for (int i = 0; i < n; i++)
for (int j = 1; j < n; j++)
if (cmp(A[j], A[j - 1])) {
struct point t = A[j];
A[j] = A[j - 1];
A[j - 1] = t;
}
}
int unique(struct point A[], int n) {
int t = 0;
for(int i = 0; i < n; i++)
if (②)
A[t++] = A[i];
return t;
}
int binary_search(struct point А[], int n, int x, int y) {
struct point p;
p.x = x;
р.y = y;
p.id = n;
int a = 0,b = n - 1;
while (a < b) {
int mid = ③;
if (④)
a = mid + 1;
else
b = mid;
}
return equals(A[a], р);
}
#define MAXN 1000
struct point A[MAXN];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &A[i].x, &A[i].y);
A[i].id = i;
}
sort(A, n);
n = unique(A, n);
int ans = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (⑤ && binary_search(A, n, A[i].x, A[j].y) && binary_search(A, n, A[j].x, A[i].y)) {
ans++;
}
printf("%d\n", ans);
return 0;
}④处应填( )
(矩形计数)平面上有n个关键点,求有多少个四条边都和x轴或者y轴平行的矩形,满足四个顶点都是关键点。给出的关键点可能有重复,但完全重合的矩形只计一次。
试补全枚举算法。
#include <stdio. h>
struct point {
int x, y, id;
};
int equals(struct point a, struct point b) {
return a.x == b.x && a.y == b.y;
}
int cmp(struct point a, struct point b) {
return ①;
}
void sort(struct point A[], int n) {
for (int i = 0; i < n; i++)
for (int j = 1; j < n; j++)
if (cmp(A[j], A[j - 1])) {
struct point t = A[j];
A[j] = A[j - 1];
A[j - 1] = t;
}
}
int unique(struct point A[], int n) {
int t = 0;
for(int i = 0; i < n; i++)
if (②)
A[t++] = A[i];
return t;
}
int binary_search(struct point А[], int n, int x, int y) {
struct point p;
p.x = x;
р.y = y;
p.id = n;
int a = 0,b = n - 1;
while (a < b) {
int mid = ③;
if (④)
a = mid + 1;
else
b = mid;
}
return equals(A[a], р);
}
#define MAXN 1000
struct point A[MAXN];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &A[i].x, &A[i].y);
A[i].id = i;
}
sort(A, n);
n = unique(A, n);
int ans = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (⑤ && binary_search(A, n, A[i].x, A[j].y) && binary_search(A, n, A[j].x, A[i].y)) {
ans++;
}
printf("%d\n", ans);
return 0;
}⑤处应填( )
在Linux系统终端中,用于列出当前目录下所含的文件和子目录的命令为( )。
二进制数001010102和000101102的和为( )。
在程序运行过程中,如果递归调用的层数过多,可能会由于( )引发错误。
以下排序方法中,( )是不稳定的。
以比较为基本运算,对于2n个数,同时找到最大值和最小值,最坏情况下需要的最小的比较次数为( )。
现有一个地址区间为0~10的哈希表,对于出现冲突情况,会往后找第一个空的地址存储(到10冲突了就从0开始往后),现在要依次存储(0,1,2,3,4,5,6,7),哈希函数为h(x)=x2 mod 11。请问7存储在哈希表哪个地址中( )。
G是一个非连通简单无向图(没有自环和重边),共有36条边,则该图至少有( )个点。
令根结点的高度为1,则一棵含有2021个结点的二叉树的高度至少为( )。
前序遍历和中序遍历相同的二叉树为且仅为( )。
定义一种字符串操作为交换相邻两个字符。将“DACFEB”变为 “ABCDEF”最少需要( )次上述操作。
有如下递归代码
solve(t, n) if t = 1 return 1 else return 5 * solve(t - 1, n) mod n
则solve(23, 23)的结果为( )。
斐波那契数列的定义为:F1=1,F2=1,Fn=Fn-1+Fn-2(n>=3)。现在用如下程序来计算斐波那契数列的第n项,其时间复杂度为( )。
F(n): if n <= 2 return 1 else return F(n - 1) + F(n - 2)
有8个苹果从左到右排成一排,你要从中挑选至少一个苹果,并且不能同时挑选相邻的两个苹果,一共有( )种方案。
设一个三位数
均为1∼9之间的整数,若以a、b、c作为三角形的三条边可以构成等腰三角形(包括等边),则这样的n有( )个。
有如下的有向图,节点为A,B,⋯,J,其中每条边的长度都标在图中。则节点A到节点J的最短路径长度为( )。
![CSP-S1提高级初赛试卷[2021] CSP-S1提高级初赛试卷[2021]](/oj/ueditor/php/upload/image/20220428/1651110064329111.png)