Skip to content

Commit 024af05

Browse files
committed
[aceptaelreto] Add C++ solution for 103 - Problemas de Herencia
1 parent 22793c1 commit 024af05

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

aceptaelreto/103-1.ans

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ABEL
2+
ABEL
3+
CAIN
4+
JUSTO
5+
ABEL

aceptaelreto/103-1.in

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
1
2+
1 0
3+
100
4+
3
5+
1 2 -1 0
6+
1000
7+
3
8+
1 2 -1 1
9+
1000
10+
1
11+
3 -1
12+
10000
13+
1
14+
3 -1
15+
2
16+
20

aceptaelreto/103.cc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// https://www.aceptaelreto.com/problem/statement.php?id=103
2+
#include <bits/stdc++.h>
3+
4+
using namespace std;
5+
const int N = 20;
6+
int p[N], n;
7+
8+
double f(double x) {
9+
double sum = 0;
10+
for (int i = 0; i <= n; i++) {
11+
double exp = 1;
12+
for (int j = 0; j < i; j++) exp *= x;
13+
sum += exp * p[i];
14+
}
15+
if (sum < 0) return 0;
16+
if (sum > 1) return 1;
17+
return sum;
18+
}
19+
20+
int main() {
21+
cin.tie(0), ios::sync_with_stdio(0);
22+
while (1) {
23+
int m;
24+
cin >> n;
25+
if (n == 20) break;
26+
for (int i = 0; i <= n; i++) cin >> p[n - i];
27+
cin >> m;
28+
double area = 0;
29+
for (int i = 0; i < m; i++) {
30+
double x = 1 / double(m);
31+
area += x * f(x * i);
32+
}
33+
if (area - 0.5 > 0.001) cout << "CAIN\n";
34+
else if (0.5 - area > 0.001)
35+
cout << "ABEL\n";
36+
else
37+
cout << "JUSTO\n";
38+
}
39+
}

aceptaelreto/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ There are solutions for the following
66
1. [100 - Constante de Kaprekar](100.cc) ([problem site](https://www.aceptaelreto.com/problem/statement.php?id=100))
77
1. [101 - Cuadrados diabólicos y esotéricos](101.cc) ([problem site](https://www.aceptaelreto.com/problem/statement.php?id=101))
88
1. [102 - Encriptación de mensajes](102.cc) ([problem site](https://www.aceptaelreto.com/problem/statement.php?id=102))
9+
1. [103 - Problemas de Herencia](103.cc) ([problem site](https://www.aceptaelreto.com/problem/statement.php?id=103))
910
1. [114 - Último dígito del factorial](114.cc) ([problem site](https://www.aceptaelreto.com/problem/statement.php?id=114))
1011
1. [116 - ¡Hola mundo!](116.cc) ([problem site](https://www.aceptaelreto.com/problem/statement.php?id=116))
1112
1. [192 - Por 3 o más 5](192.cc) ([problem site](https://www.aceptaelreto.com/problem/statement.php?id=192))

0 commit comments

Comments
 (0)