Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dia003
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joel Florentin
dia003
Commits
d7edad0d
Commit
d7edad0d
authored
Oct 21, 2021
by
Joel Florentin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mochila
parent
4b3e03e1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
3 deletions
+35
-3
.gitignore
+2
-0
Mochila.java
+33
-2
SalonBellezaV2.java
+0
-1
No files found.
.gitignore
0 → 100644
View file @
d7edad0d
*.class
\ No newline at end of file
Mochila.java
View file @
d7edad0d
...
...
@@ -29,14 +29,45 @@ public class Mochila {
Arrays
.
sort
(
cosas
,
(
a
,
b
)
->
b
.
getRatio
().
compareTo
(
a
.
getRatio
()));
int
libre
=
capacidad
;
int
cantidadLlevarElemento
=
0
;
for
(
Objeto
objeto
:
cosas
)
{
int
index_first_mejor
=
0
;
int
mejor_index
=
0
;
int
mejor_benefico
=
0
;
Objeto
objeto
;
int
beneficio
=
0
;
while
(
index_first_mejor
<
cosas
.
length
){
beneficio
=
0
;
libre
=
capacidad
;
for
(
int
i
=
index_first_mejor
;
i
<
cosas
.
length
;
i
++)
{
objeto
=
cosas
[
i
];
if
(
objeto
.
getPeso
()<=
libre
){
cantidadLlevarElemento
=
Math
.
floorDiv
(
libre
,
objeto
.
getPeso
());
libre
-=
(
cantidadLlevarElemento
*
objeto
.
getPeso
());
if
(
beneficio
==
0
)
index_first_mejor
=
i
;
beneficio
+=
(
cantidadLlevarElemento
*
objeto
.
getValor
());
}
if
(
libre
==
0
){
break
;
}
}
if
(
beneficio
>
mejor_benefico
){
mejor_index
=
index_first_mejor
;
mejor_benefico
=
beneficio
;
}
index_first_mejor
++;
}
beneficio
=
0
;
libre
=
capacidad
;
for
(
int
i
=
mejor_index
;
i
<
cosas
.
length
;
i
++)
{
objeto
=
cosas
[
i
];
if
(
objeto
.
getPeso
()<=
libre
){
cantidadLlevarElemento
=
Math
.
floorDiv
(
libre
,
objeto
.
getPeso
());
for
(
int
i
=
0
;
i
<
cantidadLlevarElemento
;
i
++)
{
for
(
int
j
=
0
;
j
<
cantidadLlevarElemento
;
j
++)
{
elementos
.
add
(
objeto
);
}
libre
-=
(
cantidadLlevarElemento
*
objeto
.
getPeso
());
beneficio
+=
(
cantidadLlevarElemento
*
objeto
.
getValor
());
}
if
(
libre
==
0
){
break
;
...
...
SalonBellezaV2.java
View file @
d7edad0d
package
t
;
public
class
SalonBellezaV2
{
public
static
void
main
(
String
[]
args
)
{
Cliente
horacio
=
new
Cliente
(
"Horacio"
,
"1312"
,
"Calle 1"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment