和上题差不多一样的搞法。
#include<iostream> #include<cstdio> #include<cstring> #include<map> #include<vector> #include<stdlib.h> using namespace std; const int maxn = 111111; int a[maxn]; int b[maxn]; int vis[maxn]; int main() { int n, mod; while (scanf("%d%d", &mod, &n), n || mod){ for (int i = 1; i <= n; i++){ scanf("%d", &a[i]); b[i] = a[i]; } for (int i = 1; i <= n; i++) b[i] += b[i - 1], b[i] %= mod; int gg = 0; for (int i = 1; i <= n; i++){ if (b[i] == 0){ for (int j = 1; j <= i; j++) printf("%d ", j); cout << endl; gg = 1; break; } } if (gg)continue; memset(vis, 0, sizeof(vis)); for (int i = 1; i <= n; i++){ if (!vis[b[i]]){ vis[b[i]] = i; } else{ for (int j = vis[b[i]] + 1; j <= i; j++) printf("%d ", j); cout << endl; gg = 1; break; } } if (!gg) puts("no sweets"); } return 0; }
时间: 2024-10-21 08:48:32