Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- enum {
- ENEMY=-1,
- NEUTRAL=0,
- ME=1
- };
- struct Factory {
- int id;
- int owner;
- int troopCount;
- int production;
- };
- struct Relation {
- Factory factory1;
- Factory factory2;
- int distance;
- };
- Relation minDistanceFromFactory(Factory, Relation*, bool);
- int factoryCount;
- int linkCount;
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- **/
- int main()
- {
- // the number of factories
- cin >> factoryCount; cin.ignore();
- // the number of links between factories
- cin >> linkCount; cin.ignore();
- Factory factories[factoryCount];
- Relation relations[linkCount];
- for (int i=0; i < factoryCount; i++) {
- Factory factory;
- factory.id = i;
- factories[i] = factory;
- }
- for (int i = 0; i < linkCount; i++) {
- int factory1;
- int factory2;
- int distance;
- cin >> factory1 >> factory2 >> distance; cin.ignore();
- relations[i].factory1 = factories[factory1];
- relations[i].factory2 = factories[factory2];
- relations[i].distance = distance;
- }
- // game loop
- while (1) {
- int entityCount; // the number of entities (e.g. factories and troops)
- cin >> entityCount; cin.ignore();
- for (int i = 0; i < entityCount; i++) {
- int entityId;
- string entityType;
- int owner;
- int arg2;
- int arg3;
- int arg4;
- int arg5;
- cin >> entityId >> entityType >> owner >> arg2 >> arg3 >> arg4 >> arg5; cin.ignore();
- if (entityType == "FACTORY") {
- factories[entityId].owner = owner;
- factories[entityId].troopCount = arg2;
- factories[entityId].production = arg3;
- }
- }
- int source = -1;
- int destination;
- int cyborgs;
- int distance = 999;
- for(int i = 0; i < factoryCount; i++) {
- if(factories[i].owner == ME) {
- if (factories[i].troopCount > 0) {
- Relation relation = minDistanceFromFactory(factories[i], relations, true);
- if (relation.distance <= distance) {
- distance = relation.distance;
- } else {
- continue;
- }
- source = i;
- if (relation.factory1.id == factories[i].id) {
- destination = relation.factory2.id;
- } else {
- destination = relation.factory1.id;
- }
- cyborgs = (factories[i].troopCount > 20) ? 20 : factories[i].troopCount;
- }
- }
- }
- if (source != -1) {
- cout << "MOVE " << source << " " << destination << " " << cyborgs << endl;
- } else {
- cout << "WAIT" << endl;
- }
- // Write an action using cout. DON'T FORGET THE "<< endl"
- // To debug: cerr << "Debug messages..." << endl;
- // Any valid action, such as "WAIT" or "MOVE source destination cyborgs"
- }
- }
- Relation minDistanceFromFactory(Factory factory, Relation* relations, bool exceptMyFactories)
- {
- int id_relation, min_distance = 999;
- for(int i=0; i < linkCount; i++) {
- if (relations[i].factory1.id == factory.id) {
- if (exceptMyFactories && relations[i].factory2.owner == ME) {
- continue;
- }
- }
- if (relations[i].factory2.id == factory.id) {
- if (exceptMyFactories && relations[i].factory1.owner == ME) {
- continue;
- }
- }
- if (relations[i].distance <= min_distance) {
- min_distance = relations[i].distance;
- cerr << min_distance << endl;
- id_relation = i;
- }
- }
- return relations[id_relation];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement