Переписать программу с java на pascal, , 50 import java.util.*; import java.io.*; public class sol_ik { private final int unit = 1000; private final int discount_per_unit = 500; private final double max_discount = 0.2; private double gettotalcost(long firstcost, long secondcost, long fullunits) { long couponsum = fullunits * discount_per_unit; double secondcostwithdiscount = secondcost - math.min(max_discount * secondcost, couponsum); return firstcost + secondcostwithdiscount; } long[] solveknapsack(long[] weights, long totalweight) { int maxunits = (int) (totalweight / unit + 1); long[] old = new long[maxunits + 1]; arrays.fill(old, totalweight); old[0] = 0; long[] cur = new long[maxunits + 1]; int n = weights.length; for (int pos = 0; pos < n; pos++) { arrays.fill(cur, totalweight); for (int units = 0; units < = maxunits; units++) { cur[units] = math.min(cur[units], old[units]); int add = (int) weights[pos] / unit; if (units - add > = 0) { cur[units] = math.min(cur[units], old[units - add] + weights[pos]); } } system.arraycopy(cur, 0, old, 0, cur.length); } return old; } public double getsolution(long[] costs) { int n = costs.length; long totalcost = 0; for (int i = 0; i < n; i++) { totalcost += costs[i]; } long[] minforunits = solveknapsack(costs, totalcost); double res = totalcost; long maxunits = totalcost / unit + 1; for (int units = 0; units < = maxunits; units++) { double cur = minforunits[units]; res = math.min(res, gettotalcost(minforunits[units], totalcost - minforunits[units], units)); } return res; } public void solve(scanner in, printwriter out) { int n = in.nextint(); long[] costs = new long[n]; for (int i = 0; i < n; i++) { costs[i] = in.nextint(); } out.printf("%.2f%n", getsolution(costs)); } public static void main(string[] args) { scanner in = new scanner(system.in); printwriter out = new printwriter(system.out); new (in, out); out.flush(); } }
177
494
Ответы на вопрос:
блок-схема:
начало|
a , b , c
|
d = b * b - 4 * a * c
|
- d > = 0 +
| |
дкн x1 =(-b + sqr(d)) / (2*a)
| |
| x2 =(-b - sqr(d)) / (2×a)
| |
| x1 , x2
| |
| |
| |
| конец |
вот и все
программа
print “количество корней квадратного уравнения“
input “ввести a, b, c: “, a, b, c
d = b * b – 4 * a * c
if d > = 0 then
if d > 0 then print “2 разных корня“ else print “2 одинаковых корня“
else print “действительных корней нет“
Популярно: Информатика
-
12dosbol27.10.2022 09:56
-
TadaseXotory03.05.2021 20:19
-
Алкадиеныч14.11.2021 03:19
-
oksanasmolko2005.09.2021 17:53
-
edbaldin201703.06.2023 22:08
-
Aidana13023428.09.2021 19:54
-
Мэйбл12345678921.03.2023 22:52
-
alinzik317.03.2020 09:59
-
владимир20306.08.2020 12:43
-
Выберитеникмен23.06.2022 01:21