### finish decomposition

 Start testing: Nov 16 22:09 ?D1??? Start testing: Nov 17 21:19 ?D1??? ---------------------------------------------------------- End testing: Nov 16 22:09 ?D1??? End testing: Nov 17 21:19 ?D1???
 ... ... @@ -3,26 +3,42 @@ // #include 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]); }
 ... ... @@ -4,18 +4,18 @@ #include #include int coef[200]; double integrationCoef[200]; int coef[1000]; double integrationCoef[1000]; 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, middle, p, deviation / 2) + simpsonIntegration(middle, 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,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.