Skip to content
GitLab
菜单
项目
群组
代码片段
帮助
帮助
支持
社区论坛
快捷键
?
提交反馈
登录/注册
切换导航
菜单
打开侧边栏
ZhengYi
C-PL-Solution
提交
75678869
提交
75678869
编辑于
11月 21, 2021
作者:
unknown
浏览文件
finish decomposition
上级
da7e0695
变更
8
Hide whitespace changes
Inline
Side-by-side
6-recursion/cmake-build-debug/CMakeFiles/decomposition.dir/decomposition.c.obj
浏览文件 @
75678869
无法预览此类型文件
6-recursion/cmake-build-debug/CMakeFiles/decomposition.dir/objects.a
浏览文件 @
75678869
无法预览此类型文件
6-recursion/cmake-build-debug/CMakeFiles/integration.dir/integration.c.obj
浏览文件 @
75678869
无法预览此类型文件
6-recursion/cmake-build-debug/CMakeFiles/integration.dir/objects.a
浏览文件 @
75678869
无法预览此类型文件
6-recursion/cmake-build-debug/Testing/Temporary/LastTest.log
浏览文件 @
75678869
Start testing: Nov 1
6
2
2:0
9 ?D1???
Start testing: Nov 1
7
2
1:1
9 ?D1???
----------------------------------------------------------
End testing: Nov 1
6
2
2:0
9 ?D1???
End testing: Nov 1
7
2
1:1
9 ?D1???
6-recursion/decomposition.c
浏览文件 @
75678869
...
...
@@ -3,26 +3,42 @@
//
#include
<stdio.h>
void
findDecomposition
(
int
n
);
int
arr
[
10005
]
=
{
1
};
int
n
;
void
findDecomposition
(
int
x
,
int
t
);
void
consolePrint
(
int
t
);
int
main
()
{
int
n
;
scanf
(
"%d"
,
&
n
);
findDecomposition
(
n
);
findDecomposition
(
n
,
1
);
printf
(
"%d"
,
n
);
return
0
;
}
void
findDecomposition
(
int
n
)
{
if
(
n
==
0
)
{
return
;
}
if
(
n
==
1
)
{
printf
(
"1
\n
"
);
}
else
{
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
printf
(
"%d "
,
i
);
findDecomposition
(
n
-
i
);
void
findDecomposition
(
int
x
,
int
t
)
{
int
i
;
for
(
i
=
arr
[
t
-
1
];
i
<=
x
;
i
++
)
{
if
(
i
<
n
)
{
arr
[
t
]
=
i
;
x
-=
i
;
if
(
x
==
0
)
{
// output
consolePrint
(
t
);
}
else
{
// x > 0则继续递归
findDecomposition
(
x
,
t
+
1
);
}
// 回溯
x
+=
i
;
}
}
}
void
consolePrint
(
int
t
)
{
for
(
int
i
=
1
;
i
<
t
;
i
++
)
{
printf
(
"%d "
,
arr
[
i
]);
}
printf
(
"%d
\n
"
,
arr
[
t
]);
}
6-recursion/integration.c
浏览文件 @
75678869
...
...
@@ -4,18 +4,18 @@
#include
<stdio.h>
#include
<math.h>
int
coef
[
2
00
];
double
integrationCoef
[
2
00
];
int
coef
[
10
00
];
double
integrationCoef
[
10
00
];
int
coefNumber
;
const
double
deviation
=
1e-5
;
int
p
;
double
calculate
(
double
x
);
double
calculateInt
(
double
x
,
int
p
);
double
simpsonIntegration
(
double
left
,
double
right
,
int
p
,
double
deviation
);
double
simpsonMethod
(
double
left
,
double
right
,
int
p
);
double
f
(
double
x
);
double
simpsonIntegration
(
double
left
,
double
right
,
double
ans
,
double
deviation
,
int
step
);
double
simpsonMethod
(
double
left
,
double
right
);
int
main
()
{
int
p
;
double
deviation
=
1e-6
;
scanf
(
"%d %d"
,
&
coefNumber
,
&
p
);
for
(
int
i
=
0
;
i
<=
coefNumber
;
i
++
)
{
scanf
(
"%d"
,
&
coef
[
i
]);
...
...
@@ -37,7 +37,7 @@ int main() {
ans
=
calculate
(
b
)
-
calculate
(
a
);
}
else
{
// adaptive simpson's method
ans
=
simpsonIntegration
(
a
,
b
,
p
,
deviation
);
ans
=
simpsonIntegration
(
a
,
b
,
simpsonMethod
(
a
,
b
)
,
deviation
,
12
);
}
printf
(
"%lf"
,
ans
);
...
...
@@ -56,7 +56,7 @@ double calculate(double x) {
return
ans
;
}
double
calculateInt
(
double
x
,
int
p
)
{
double
f
(
double
x
)
{
double
ans
=
0
.
0
;
double
product
=
1
;
...
...
@@ -68,24 +68,20 @@ double calculateInt(double x, int p) {
return
pow
(
ans
,
p
);
}
double
simpsonIntegration
(
double
left
,
double
right
,
int
p
,
double
deviation
)
{
double
middle
=
(
right
+
left
)
/
2
.
0
;
double
sl
=
simpsonMethod
(
left
,
middle
,
p
);
double
sr
=
simpsonMethod
(
middle
,
right
,
p
);
double
s
=
simpsonMethod
(
left
,
right
,
p
);
if
(
fabs
(
sl
+
sr
-
s
)
<=
15
*
deviation
)
{
return
sl
+
sr
+
(
sl
+
sr
-
s
)
/
15
;
double
simpsonIntegration
(
double
left
,
double
right
,
double
ans
,
double
eqs
,
int
step
)
{
double
mid
=
(
right
+
left
)
/
2
.
0
;
double
fl
=
simpsonMethod
(
left
,
mid
);
double
fr
=
simpsonMethod
(
mid
,
right
);
if
(
fabs
(
fl
+
fr
-
ans
)
<=
15
*
eqs
||
step
<
0
)
{
return
fl
+
fr
+
(
fl
+
fr
-
ans
)
/
15
;
}
else
{
// 误差除2
return
simpsonIntegration
(
left
,
mid
dle
,
p
,
deviation
/
2
)
+
simpsonIntegration
(
mid
dle
,
right
,
p
,
deviation
/
2
);
return
simpsonIntegration
(
left
,
mid
,
fl
,
eqs
/
2
,
step
-
1
)
+
simpsonIntegration
(
mid
,
right
,
fr
,
eqs
/
2
,
step
-
1
);
}
}
double
simpsonMethod
(
double
left
,
double
right
,
int
p
)
{
double
simpsonMethod
(
double
left
,
double
right
)
{
// 用辛普森公式计算的值
double
middle
=
(
right
+
left
)
/
2
.
0
;
double
ans1
=
4
*
calculateInt
(
middle
,
p
);
double
ans2
=
calculateInt
(
left
,
p
);
double
ans3
=
calculateInt
(
right
,
p
);
return
(
right
-
left
)
*
(
ans1
+
ans2
+
ans3
)
/
6
;
return
(
right
-
left
)
*
(
4
*
f
(
middle
)
+
f
(
left
)
+
f
(
right
))
/
6
;
}
6-recursion/triangle.c
浏览文件 @
75678869
...
...
@@ -6,6 +6,7 @@
void
drawTriangle
(
int
n
);
int
main
()
{
// 本题还没做完
int
n
;
scanf
(
"%d"
,
&
n
);
...
...
编辑
预览
Supports
Markdown
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录