Go to diff to previous submission
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <iostream> #include <algorithm> #include <vector> #include <string> #include <map> #include <queue> #include <deque> #include <stack> #include <set> //~ using namespace std; typedef long double num; typedef long long int lint; typedef struct { int x, y; } intpoint; typedef struct { num x, y; } numpoint; typedef struct { lint x, y; } lintpoint; #define EPS (1e-7L) #define PI (4.0L * atanl(1.0L)) #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) #define abs(a) ((a) < 0 ? -(a) : (a)) int main(int argc, char *argv[]) { while (true) { int ants, len; bool existL = false, existR = false, collision; if (2 != scanf("%u %u\n", &len, &ants)) break; int maxL = 0, minR = len, mindist = len; std::vector<int> antssssss; for (int ant = 0; ant < ants; ant++) { int start; char dir; scanf("%u %c\n", &start, &dir); if (dir == 'L') { existL = true; maxL = max(maxL, start); } else if (dir == 'R') { existR = true; minR = min(minR, start); } int aux = len%2 ? min(abs(len/2 - start), abs(len/2 + 1 - start)) : abs((len >>1) - start); if (aux < mindist) { antssssss.clear(); antssssss.push_back(start); mindist = aux; } else if(aux == mindist) antssssss.push_back(start); } int L = maxL, R = len - minR; if (existL && existR) { if (minR < maxL) { if(antssssss.size() == 2) printf("The last ant will fall down in %d seconds - started at %d and %d.\n", max(L, R), antssssss[0], antssssss[1]); else printf("The last ant will fall down in %d seconds - started at %d.\n", max(L, R), antssssss[0]); } } else if (existR) { printf("The last ant will fall down in %d seconds - started at %d.\n", R, minR); } else if (existL) { printf("The last ant will fall down in %d seconds - started at %d.\n", L, maxL); } else { // not gonna happen } } return 0; }
--- c4.s901.cteam101.ants.cpp.0.ants.cpp +++ c4.s922.cteam101.ants.cpp.0.ants.cpp @@ -44,7 +44,4 @@ - bool hasR = false, hasL = false; - int startR = INT_MAX, startL = 0; - for (int ant = 0; ant < ants; ant++) { int start; @@ -53,16 +50,10 @@ scanf("%u %c\n", &start, &dir); - if (dir == 'L' && startL <= start) { + if (dir == 'L') { existL = true; maxL = max(maxL, start); - - hasL = true; - startL = start; - } else if (dir == 'R' && start <= startR) { + } else if (dir == 'R') { existR = true; minR = min(minR, start); - - hasR = true; - startR = start; } int aux = len%2 ? min(abs(len/2 - start), abs(len/2 + 1 - start)) : abs((len >>1) - start); @@ -76,10 +67,9 @@ if(aux == mindist) antssssss.push_back(start); - } - int L = startL, R = len - startR; + int L = maxL, R = len - minR; if (existL && existR) { if (minR < maxL) { @@ -90,7 +80,7 @@ } } else if (existR) { - printf("The last ant will fall down in %d seconds - started at %d.\n", R, startR); + printf("The last ant will fall down in %d seconds - started at %d.\n", R, minR); } else if (existL) { - printf("The last ant will fall down in %d seconds - started at %d.\n", L, startL); + printf("The last ant will fall down in %d seconds - started at %d.\n", L, maxL); } else { // not gonna happen