intmain() { int kase, n, m, s, e, list[150]; scanf(" %d", &kase); while (kase--) { scanf(" %d %d", &n, &m); s = 0, e = n * m - 1; for (int i = 0; i <= e; i++) scanf(" %d", &list[i]); while (list[s] == list[e]) { if (s > e) break; s++, e--; } puts(s < e ? "keep defending" : "go forward"); } return0; }
intmain() { int n , num , sum; while (scanf(" %d", &n) == 1) { sum = 0; for (int i = 1; i <= n; i++) { scanf(" %d", &num); sum += num * i; } printf("%d\n", sum); } return0; }
voiddfs(int sum, int start, int depth) { for (int i = start; i < n; i++) { next = sum + list[i]; if (next >= m) { if (next == m) { for (int j = 0; j < depth; j++) printf("%d ", output[j]); printf("%d\n", list[i]); noAns = 0; } if (list[i] < list[i + 1]) return; } output[depth] = list[i]; if (next + list[i] <= m) dfs(next, i + 1, depth + 1); } }
intmain() { while (scanf(" %d %d", &n, &m) == 2) { noAns = 1; for (int i = 0; i < n; i++) scanf(" %d", &list[i]); qsort(list, n, sizeof(int), cmp); dfs(0, 0, 0); if (noAns) puts("-1"); } return0; }
intmain() { for (int i = 0; i < MAX; i++) sort[i] = &list[i]; int n; while (scanf(" %d", &n) == 1) { for (int i = 0; i < n; i++) scanf(" %d %d", &list[i].x, &list[i].y); qsort(sort, n, sizeof(Point*), cmp); for (int i = 0; i < n; i++) printf("%d %d\n", sort[i]->x, sort[i]->y); } return0; }
voidSetPrimeList() { char isNot[MAX] = { 0 }; primeList[pLen++] = 2; for (int i = 3; i < MAX; i += 2) { if (isNot[i])continue; primeList[pLen++] = i; for (int j = i << 1; j < MAX; j += i) isNot[j] = 1; } }
charisPrime(int n) { if (n < MAX) { int* item = (int*)bsearch(&n, primeList, pLen, sizeof(int), cmp); return (item != NULL); } else { for (int i = 0, max = sqrt(n); primeList[i] <= max; i++) { if (!(n % primeList[i])) return0; } return1; } }
intmain() { SetPrimeList(); int n, ans; while (scanf(" %d", &n) == 1) { if (isPrime(n)) printf("%d\n", n); else { ans = 0; for (int i = 0; n > 1; i++) { while (!(n % primeList[i])) { n /= primeList[i]; ans += primeList[i]; } } printf("%d\n", ans); } } return0; }