-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,081 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
3 1 2 3 | ||
5 10 15 20 30 50 | ||
4 100 200 300 400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
11 17 23 30 50 | ||
100 200 300 400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
# nce Problem : Array Practice | ||
时间限制: 1 Sec 内存限制: 4 MB | ||
题目描述整数序列是一串按特定顺序排列的整数,整数序列的长度是序列中整数的个数,不可定义长度为负数的整数序列。 | ||
# Sequence Problem : Array Practice | ||
Time Limit: 1 Sec Memory Limit: 4 MB | ||
|
||
|
||
## Description | ||
整数序列是一串按特定顺序排列的整数,整数序列的长度是序列中整数的个数,不可定义长度为负数的整数序列。 | ||
两整数序列A、B的和定义为一个新的整数序列C,序列C的长度是A、B两者中较长的一个,序列C的每个位置上的整数都是A、B对应位置之和。若序列A、B不等长,不妨假设A比B整数多,那么序列C中多出B的那部分整数视作A的对应位置上的整数与0相加。 | ||
你的任务是计算符合某些要求的整数序列的和,这些序列中的整数都是小于1000的非负整数。输入输入为多行,直到文件末尾结束。每行第一个整数为N(N<=1000),后接一个长度为N的整数序列。输出对输入的整数序列两两相加:第1行和第2行相加、第3行和第4行相加……按顺序输出结果:每行输出一个整数序列,每两个整数之间用一个空格分隔。若序列数目不为偶数,则视作补一个长度为0的整数序列相加。 | ||
值得注意的是一个长度为0的整数序列也应该有输出,即使没有整数输出,也应该占有一行,因为“每行输出一个整数序列”。样例输入3 1 2 3 | ||
你的任务是计算符合某些要求的整数序列的和,这些序列中的整数都是小于1000的非负整数。 | ||
|
||
## Input | ||
输入为多行,直到文件末尾结束。每行第一个整数为N(N<=1000),后接一个长度为N的整数序列。 | ||
|
||
## Output | ||
对输入的整数序列两两相加:第1行和第2行相加、第3行和第4行相加……按顺序输出结果:每行输出一个整数序列,每两个整数之间用一个空格分隔。若序列数目不为偶数,则视作补一个长度为0的整数序列相加。 | ||
值得注意的是一个长度为0的整数序列也应该有输出,即使没有整数输出,也应该占有一行,因为“每行输出一个整数序列”。 | ||
|
||
## Sample Input | ||
``` | ||
3 1 2 3 | ||
5 10 15 20 30 50 | ||
4 100 200 300 400样例输出11 17 23 30 50 | ||
100 200 300 400提示这里最少要用到一个数组来存数整数序列或整数序列的和。 | ||
4 100 200 300 400 | ||
``` | ||
## Sample Output | ||
``` | ||
11 17 23 30 50 | ||
100 200 300 400 | ||
``` | ||
|
||
## HINT | ||
这里最少要用到一个数组来存数整数序列或整数序列的和。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
3 | ||
3 1 2 3 | ||
5 10 15 20 30 50 | ||
4 100 200 300 400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
11 17 23 30 50 | ||
110 215 320 430 50 | ||
100 200 300 400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Sequence Problem (IV) : Function Practice (Append Code) | ||
Time Limit: 1 Sec Memory Limit: 4 MB | ||
|
||
|
||
## Description | ||
整数序列是一串按特定顺序排列的整数,整数序列的长度是序列中整数的个数,不可定义长度为负数的整数序列。 | ||
两整数序列A、B的和定义为一个新的整数序列C,序列C的长度是A、B两者中较长的一个,序列C的每个位置上的整数都是A、B对应位置之和。若序列A、B不等长,不妨假设A比B整数多,那么序列C中多出B的那部分整数视作A的对应位置上的整数与0相加。 | ||
你的任务是计算符合某些要求的整数序列的和,这些序列中的整数都是小于1000的非负整数。 | ||
----------------------------------------------------------------------------- | ||
编写以下函数,使append.c中的main()函数能正确运行: | ||
原型:int max(int a, int b); | ||
功能:返回a和b中较大的一个int值。 | ||
原型:int init_seq(int seq[], int size); | ||
功能:把int数组seq[]中的前size个元素初始化为0。 | ||
原型:int get_seq(int seq[]); | ||
功能:按输入格式的要求,读取size个元素存放在seq[],返回读到的元素个数。 | ||
原型:int put_seq(int seq[], int size); | ||
功能:按输出格式的要求,把seq[]中的前size个元素输出。 | ||
原型:int add_seq(int sum_seq[], int add_seq[], int size); | ||
功能:把sum_seq[]和add_seq[]中的前size个元素相加,结果存储sum_seq[]中。 | ||
|
||
|
||
|
||
## Input | ||
输入的第一行为一个整数M(M>0),后面有M行输入。每行第一个整数为N(N<=1000),后接一个长度为N的整数序列。 | ||
|
||
## Output | ||
对输入的整数序列两两相加:第1行和第2行相加、第2行和第3行相加……按顺序输出结果:每行输出一个整数序列,每两个整数之间用一个空格分隔。若最后序列不足两个,则视作补一个长度为0的整数序列相加。 | ||
值得注意的是一个长度为0的整数序列也应该有输出,即使没有整数输出,也应该占有一行,因为“每行输出一个整数序列”。 | ||
|
||
## Sample Input | ||
``` | ||
3 | ||
3 1 2 3 | ||
5 10 15 20 30 50 | ||
4 100 200 300 400 | ||
``` | ||
## Sample Output | ||
``` | ||
11 17 23 30 50 | ||
110 215 320 430 50 | ||
100 200 300 400 | ||
``` | ||
|
||
## HINT | ||
append.c中的main()函数简述: | ||
1. 定义两个数组odd_seq[]和even_seq[],分别存储奇数行输入的序列和偶数行输入序列,odd_size和even_size是输入的序列元素个数。 | ||
2. 输入总行数m; | ||
3. 初始化odd_seq[]的全部元素,输入第一行序列,存入odd_seq[],元素个数存入odd_size; | ||
4. 从第2行至第m行重复以下步骤: | ||
4.1 要输入的是偶数行:even_seq[]全体清0,读even_seq[],把even_seq[]加到odd_seq[]上,输出odd_seq[]; | ||
4.2 要输入的是奇数行时与偶数行操作的变量相反,步骤一致; | ||
5. 输出最后一行。 | ||
|
||
|
||
## Append Code | ||
### append.c | ||
```c | ||
int main() | ||
{ | ||
int odd_seq[MAX_SIZE], odd_size; | ||
int even_seq[MAX_SIZE], even_size; | ||
int m, i, put_size; | ||
|
||
scanf("%d", &m); | ||
init_seq(odd_seq, MAX_SIZE); | ||
odd_size = get_seq(odd_seq); | ||
for(i = 2; i <= m; i++) | ||
{ | ||
if(i % 2 == 0) | ||
{ | ||
init_seq(even_seq, MAX_SIZE); | ||
even_size = get_seq(even_seq); | ||
put_size = max(odd_size, even_size); | ||
add_seq(odd_seq, even_seq, put_size); | ||
put_seq(odd_seq, put_size); | ||
} | ||
else | ||
{ | ||
init_seq(odd_seq, MAX_SIZE); | ||
odd_size = get_seq(odd_seq); | ||
put_size = max(odd_size, even_size); | ||
add_seq(even_seq, odd_seq, put_size); | ||
put_seq(even_seq, put_size); | ||
} | ||
} | ||
if(m % 2 == 0) | ||
put_seq(even_seq, even_size); | ||
else | ||
put_seq(odd_seq, odd_size); | ||
return 0; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
2 2 3 | ||
1 1 | ||
2 0 | ||
0 2 3 | ||
1 1 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1 3 5 | ||
0 4 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# 编写函数:矩阵乘法 (Append Code) | ||
Time Limit: 1 Sec Memory Limit: 128 MB | ||
|
||
|
||
## Description | ||
|
||
给出一个m行n列的矩阵A和一个n行q列的矩阵B,求它们的乘积。 | ||
|
||
----------------------------------------------------------------------------- | ||
结合“Append Code”中的代码,编写以下函数(形参中ma[][]的数组大小需自己补全): | ||
原型:int get_matrix(int ma[][], int m, int n); | ||
功能:遵循样例输入的格式读取一个m行n列的矩阵存储在ma[][]里。 | ||
原型:int put_matrix(int ma[][], int m, int n); | ||
功能:按格式输出一个m行n列矩阵ma[][]的所有元素。 | ||
原型:int mul_matrix(int pr[][], int m1[][], int m2[][], int m, int n, int q); | ||
功能:计算m行n列的矩阵m1[][]和n行q列的矩阵m2[][]的乘积pr[][]。 | ||
函数的调用格式见“Append Code”。 | ||
|
||
|
||
## Input | ||
输入分为三部分,首先输入三个正整数m,n,q,其次是一个m行n列的矩阵A,最后是一个n行q列的矩阵B,矩阵的元素均为整数。m、n、q均不超过100。 | ||
|
||
## Output | ||
输出一个m行q列的矩阵。矩阵的每行元素输出为一行,矩阵每列元素间一个用空格分开。 | ||
|
||
## Sample Input | ||
``` | ||
2 2 3 | ||
1 1 | ||
2 0 | ||
0 2 3 | ||
1 1 2 | ||
``` | ||
## Sample Output | ||
``` | ||
1 3 5 | ||
0 4 6 | ||
``` | ||
|
||
## HINT | ||
定义多维维数组做形参时,元素的个数要小心定义。 | ||
|
||
## Append Code | ||
### append.c | ||
```c | ||
int main() | ||
{ | ||
int m, n, q; | ||
int product[MAX_SIZE][MAX_SIZE]; | ||
int matrix1[MAX_SIZE][MAX_SIZE]; | ||
int matrix2[MAX_SIZE][MAX_SIZE]; | ||
|
||
scanf("%d%d%d", &m, &n, &q); | ||
get_matrix(matrix1, m, n); | ||
get_matrix(matrix2, n, q); | ||
mul_matrix(product, matrix1, matrix2, m, n, q); | ||
put_matrix(product, m, q); | ||
|
||
return 0; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
2 | ||
4 | ||
11 1 5 -4 13 | ||
-2 8 2 3 11 | ||
3 -2 10 4 15 | ||
1 3 -2 17 19 | ||
3 | ||
2 1 1 28 | ||
5 2 2 66 | ||
10 5 4 137 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
x1=1.000 | ||
x2=1.000 | ||
x3=1.000 | ||
x4=1.000 | ||
|
||
x1=10.000 | ||
x2=5.000 | ||
x3=3.000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# 解方程组 | ||
Time Limit: 1 Sec Memory Limit: 128 MB | ||
|
||
|
||
## Description | ||
给定一个n维的线性方程组,可确保方程组有唯一解,编程求出方程组的解。 | ||
例如,有方程组 | ||
|
||
解得 | ||
|
||
|
||
## Input | ||
输入的第一个为整数M,接下来有M个测试数据,即M个方程组。每组测试数据首先输入一个整数n(n<=50),表示该方程组有n个未知数,接下来是一个n阶的系数矩阵。 | ||
|
||
## Output | ||
对于每一组数据,输出n个未知数的解。每两组测试数据之间输出一个空行。 | ||
请注意未知数的下标和输出顺序与输入的对应关系。 | ||
|
||
|
||
## Sample Input | ||
``` | ||
2 | ||
4 | ||
11 1 5 -4 13 | ||
-2 8 2 3 11 | ||
3 -2 10 4 15 | ||
1 3 -2 17 19 | ||
3 | ||
2 1 1 28 | ||
5 2 2 66 | ||
10 5 4 137 | ||
``` | ||
## Sample Output | ||
``` | ||
x1=1.000 | ||
x2=1.000 | ||
x3=1.000 | ||
x4=1.000 | ||
x1=10.000 | ||
x2=5.000 | ||
x3=3.000 | ||
``` | ||
|
||
## HINT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
2 | ||
0 1 1 0 1 0 | ||
1 0 0 1 1 1 | ||
0 0 1 0 0 1 | ||
1 0 0 1 0 1 | ||
0 1 1 1 0 0 | ||
|
||
0 0 1 0 1 0 | ||
1 0 1 0 1 1 | ||
0 0 1 0 1 1 | ||
1 0 1 1 0 0 | ||
0 1 0 1 0 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
PUZZLE #1 | ||
1 0 1 0 0 1 | ||
1 1 0 1 0 1 | ||
0 0 1 0 1 1 | ||
1 0 0 1 0 0 | ||
0 1 0 0 0 0 | ||
PUZZLE #2 | ||
1 0 0 1 1 1 | ||
1 1 0 0 0 0 | ||
0 0 0 1 0 0 | ||
1 1 0 1 0 1 | ||
1 0 1 1 0 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# 高斯消元法 | ||
Time Limit: 1 Sec Memory Limit: 128 MB | ||
|
||
|
||
## Description | ||
给你一个5*6的矩阵,矩阵里每一个单元都有一个灯和一个开关,如果按下此开关,那么开关所在位置的那个灯和开关前后左右的灯的状态都会改变 (即由亮到不亮或由不亮到亮)。给你一个初始的灯的状态,问怎样控制每一个开关使得所有的灯最后全部熄灭。 | ||
|
||
|
||
## Input | ||
输入第一行整数N,代表有N组测试用例,每一组测试用例是一个5*6的矩阵,在5*6的矩阵里,0代表灯关闭,1代表灯开着。 | ||
|
||
|
||
## Output | ||
对于每一组数据,输出第一行包括字符串:"PUZZLE #m",m是代表的是第m组数据,接着输出一个包含0,1的5*6的矩阵,(ij)处的0代表(i,j)处的开关没有按下,(ij)处的1代表(i,j)处的开关按下。 | ||
|
||
|
||
## Sample Input | ||
``` | ||
2 | ||
0 1 1 0 1 0 | ||
1 0 0 1 1 1 | ||
0 0 1 0 0 1 | ||
1 0 0 1 0 1 | ||
0 1 1 1 0 0 | ||
0 0 1 0 1 0 | ||
1 0 1 0 1 1 | ||
0 0 1 0 1 1 | ||
1 0 1 1 0 0 | ||
0 1 0 1 0 0 | ||
``` | ||
## Sample Output | ||
``` | ||
PUZZLE #1 | ||
1 0 1 0 0 1 | ||
1 1 0 1 0 1 | ||
0 0 1 0 1 1 | ||
1 0 0 1 0 0 | ||
0 1 0 0 0 0 | ||
PUZZLE #2 | ||
1 0 0 1 1 1 | ||
1 1 0 0 0 0 | ||
0 0 0 1 0 0 | ||
1 1 0 1 0 1 | ||
1 0 1 1 0 1 | ||
``` | ||
|
||
## HINT | ||
找出每个灯和开关之间的关系,列出方程组求解。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
2 | ||
0 0 | ||
1 0 | ||
1 1 | ||
0 1 | ||
0 0 | ||
1 2 | ||
0 1 | ||
-1 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Case 1: convex | ||
Case 2: concave |
Oops, something went wrong.