UVA 11292 Dragon of Loowater
2015-10-01 20:59
459 查看
#include<stdio.h> #include<stdlib.h> #define MAX 20000 int headHight[MAX + 1]; int knightHight[MAX + 1]; int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b; } int main() { int numOfHeads, numOfKnights; while (scanf("%d%d", &numOfHeads, &numOfKnights) != EOF){ if (numOfHeads == 0 && numOfKnights == 0) return 0; int head; for (head = 1; head <= numOfHeads; head++) scanf("%d", &headHight[head]); int knight; for (knight = 1; knight <= numOfKnights; knight++) scanf("%d", &knightHight[knight]); qsort(&headHight[1], numOfHeads, sizeof(headHight[0]), cmp); qsort(&knightHight[1], numOfKnights, sizeof(knightHight[0]), cmp); knight = 1; int fail = 0; int pay = 0; for (head = 1; head <= numOfHeads; head++){ while (knight <= numOfKnights && knightHight[knight] < headHight[head]) knight++; if (knight > numOfKnights){ fail = 1; break; } pay += knightHight[knight]; knight++; } if (fail) printf("Loowater is doomed!\n"); else printf("%d\n", pay); } return 0; }
相关文章推荐
- 1.10055 - Hashmat the brave warrior
- 2.10071 - Back to High School Physics
- 3.458 - The Decoder
- 4.694 - The Collatz Sequence
- 6.494 - Kindergarten Counting Game
- 7.490 - Rotating Sentences
- 8.414 - Machined Surfaces
- 9.488 - Triangle Wave
- A.457 - Linear Cellular Automata
- B.489 - Hangman Judge
- C.445 - Marvelous Mazes
- 1.10494 - If We Were a Child Again
- 2.424 - Integer Inquiry
- 3.10250 - The Other Two Trees
- 5.465 - Overflow
- 6.113 - Power of Cryptography
- 7.10161 - Ant on a Chessboard
- 8.621 - Secret Research
- 9.401 - Palindromes
- A.537 - Artificial Intelligence?