ens-ulm-1-2015

google hashcode 2015 source for team ens-ulm-1
git clone https://a3nm.net/git/ens-ulm-1-2015/
Log | Files | Refs

commit f3916a872e3fae998bd3cedf7380e2f885cb4d04
parent 358f5019490451eec44efd9d0c397c2ed37a9989
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Thu, 12 Mar 2015 19:54:20 +0100

fix

Diffstat:
a3nm/server.cpp | 18++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/a3nm/server.cpp b/a3nm/server.cpp @@ -14,8 +14,8 @@ struct Server{ int id, z, c; Server(int id=0, int z=0, int c=0) : id(id), z(z), c(c) {} bool operator< (const Server &s) const{ - if (z*s.c == s.z*c) return z < s.z; - return z*s.c < s.z*c; + if (z*s.c == s.z*c) return z > s.z; + return z*s.c > s.z*c; } }; @@ -49,6 +49,16 @@ int main() { reverse(serv.begin(), serv.end()); // now keep only the servers we will use + int free = R * S - U; + + int i; + for (i = 0; i < M; i++) { + free -= serv[i].c; + if (free <= 0) + break; + } + + sort(serv.begin(), serv.begin() + i); for (int i = 0; i < M; i++) { fposr[i] = fposc[i] = fgroup[i] = -1; @@ -107,6 +117,8 @@ int main() { fposr[serv[i].id] = whererow; fposc[serv[i].id] = wherecol; fgroup[serv[i].id] = idx; + } else { + printf("CANNOT PLACE!!\n"); } } @@ -131,6 +143,8 @@ int main() { putchar('\n'); } + printf("CUT\n"); + // display sol for (int i= 0 ; i < M; i++) { if (fposr[i] >= 0)