#include <stdio.h> int main() { int one, two, three, four, five, six; int num = 0; while (scanf(“%d%d%d%d%d%d”, &one, &two, &three, &four, &five, &six) == 6) { if (one == 0 && two == 0 && three == 0 && four == 0 && five == 0 && six == 0) { break; } num = six; num += five; if (one > five * 11) { one -= five * 11; } else { one = 0; } num += four; if (two > four * 5) { two -= four * 5; } else { if (one > four * 5 * 4 – two * 4) { one -= four * 5 * 4 – two * 4; } else { one = 0; } two = 0; } num += three / 4; three = three % 4; if (three == 1) { if (two > 5) { two -= 5; if (one > 7) { one -= 7; } else { one = 0; } } else { if (one > 27 – two * 4) { one -= 27 – two * 4; } else { one = 0; } two = 0; } ++num; } if (three == 2) { if (two > 3) { two -= 3; if (one > 6) { one -= 6; } else { one = 0; } } else { if (one > 18 – two * 4) { one -= 18 – two * 4; } else { one = 0; } two = 0; } ++num; } if (three == 3) { if (two > 1) { two -= 1; if (one > 5) { one -= 5; } else { one = 0; } } else { if (one > 9 – two * 4) { one -= 9 – two * 4; } else { one = 0; } two = 0; } ++num; } num += two / 9; two = two % 9; if (two) { if (one > 36 – two * 4) { one -= 36 – two * 4; } else { one = 0; } ++num; } num += one / 36; if (one % 36) { ++num; } printf(“%d\n”, num); } return 0; }
#include <stdio.h> #include <stdlib.h> #define M_MAX 100 + 2 struct Area { int start; int end; }; int CompareArea(const void *elem1, const void *elem2) { return ((Area*)elem1)->start - ((Area*)elem2)->start; } int main() { Area area[M_MAX], temp; int L = 0; int M = 0; int count = 0; scanf("%d%d", &L, &M); for (int i = 0; i < M; ++i) { scanf("%d%d", &area[i].start, &area[i].end); } qsort(area, M, sizeof(Area), CompareArea);
temp = area[0]; for (int i = 1; i < M; ++i) { if (area[i].start <= temp.end) { if (area[i].end > temp.end) { temp.end = area[i].end; } } else { count += temp.end - temp.start + 1; temp = area[i]; } } count += temp.end - temp.start + 1;