// UVa 10474 - Where is the Marble? #include <stdio.h> #include <string.h> const int LIMIT = 10001; int numberOfQueries; int numberOfMarbles; int count[LIMIT]; int sum[LIMIT]; int queries[LIMIT]; int caseNumber = 0; bool readInput(); void sumCounts(); void solveQueries(); int main() { while (readInput()) { sumCounts(); solveQueries(); } return 0; } bool readInput() { scanf("%d", &numberOfMarbles); scanf("%d", &numberOfQueries); if (numberOfMarbles == 0 && numberOfQueries == 0) return false; caseNumber++; memset(count, 0, sizeof(count)); for (int position = 1; position <= numberOfMarbles; position++) { int writtenOnMarble; scanf("%d", &writtenOnMarble); count[writtenOnMarble]++; } for (int i = 0; i < numberOfQueries; i++) scanf("%d", &queries[i]); return true; } void sumCounts() { memset(sum, 0, sizeof(sum)); sum[0] = count[0]; for (int i = 1; i <= LIMIT; i++) sum[i] = sum[i - 1] + count[i]; } void solveQueries() { printf("CASE# %d:\n", caseNumber); for (int i = 0; i < numberOfQueries; i++) { int query = queries[i]; if (count[query] == 0) { printf("%d not found\n", query); } else { int marblesBefore = query == 0 ? 1 : sum[query - 1]; printf("%d found at %d\n", query, marblesBefore + 1); } } }
Monday, March 13, 2017
UVa 10474 - Where is the Marble?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment