Link: Ultraviolet A 11237-Halloween treats
There are c children who want to go to the neighbor's house to ask for candy. There are n neighbors who only provide a fixed number of sweets. The bear children do not conflict with each other, I decided to distribute the obtained candy evenly. I asked if I could evenly distribute the candy from those neighbors. Note that N is greater than or equal to C.
Solution concept: Drawer principle, finding the prefix and number of sequences, there are N. After the prefix and Modulo for C are obtained, the theorem of the remainder series must be in the range of 0 ~ If the value is 0, the answer is needless to say. If the prefix and the remainder of the two ends indicate that the sum of the middle section is a multiple of C. And because N is greater than or equal to C, there must be a solution for getting 0, so the number of N corresponds to the location of C-1, and there must be the same remainder.
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 100000;int a[maxn+5], s[maxn+5], vis[maxn+5];int main () { int c, n; while (scanf("%d%d", &c, &n) == 2 && c + n) { for (int i = 1; i <= n; i++) scanf("%d", &a[i]); memset(vis, -1, sizeof(vis)); vis[0] = s[0] = 0; for (int i = 1; i <= n; i++) { s[i] = (s[i-1] + a[i]) % c; if (vis[s[i]] == -1) vis[s[i]] = i; else { for (int j = vis[s[i]] + 1; j <= i; j++) printf("%d%c", j, j == i ? ‘\n‘ : ‘ ‘); break; } } } return 0;}