Created
July 4, 2011 17:04
-
-
Save niklasfi/1063621 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "container.h" | |
unsigned int container::room_remaining() const{ | |
return (unsigned int)(size - room_used); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <queue> | |
#include <vector> | |
struct object; | |
struct container{ | |
unsigned int size; | |
unsigned int room_used; | |
unsigned int cycles_max; | |
unsigned int cycles_cur; | |
unsigned int freeze_time; | |
std::priority_queue<object> inside; | |
//std::priority_queue<object*,std::vector<object*>, std::greater<object>> outside; | |
unsigned int room_remaining() const; | |
container(){ | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "object.h" | |
/* | |
unsigned int initcycle, weight, value; | |
object::object(const container& parent, unsigned int weight, unsigned int value): | |
parent(&parent),initcycle(curcycle), weight(weight), value(value){}; | |
*/ | |
bool object::operator>(const object& o) const{ | |
if(available() != o.available()) return available(); | |
else if(value != o.value) return value > o.value; | |
else if(weight != o.weight) return weight < o.weight; | |
else return false; | |
} | |
bool object::operator<(const object& o) const{ | |
return o > *this; | |
} | |
bool object::available() const{ | |
return parent->cycles_cur - initcycle > parent->freeze_time; | |
} | |
bool object::fits() const{ | |
return parent->room_remaining() >= weight; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
struct container; | |
struct object{ | |
public: | |
container* parent; | |
unsigned int initcycle; | |
unsigned int weight; | |
unsigned int value; | |
object(const container& parent, unsigned int weight, unsigned int value); | |
bool operator<(const object& o) const; | |
bool operator>(const object& o) const; | |
bool available() const; | |
bool fits() const; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment