Description
Every year there isThe same problem at Halloween:each neighbour isOnly willing to give a certain total number of sweets on the day, no matter how many children call on him, so it may Happ En, a child wouldGetNothingifIt isToo late. To avoid conflicts, the children has decided they would put all sweets together and then divide them evenly among Themselv Es. From last year's experience of Halloween they know how many sweets they get from each neighbour. Since They care more about justice than on the number of sweets they get, they want to select a subset of the neighbour s to visit, so, and sharing every child receives the same number of sweets. They'll is not satisfied if they has any sweets left which cannot is divided.Your Job isTo help the children and present a solution.
Input
case contains integers c and n (1100000), the number of children and the number of Neighbou RS, respectively. The next line contains nspace separated integers a1, ..., an (1100000wheregetif< /c8> case was followed by and zeros.
Output
Case Select is where " No Sweets " if where each child gets at least a sweet, you may print any of them.
Sample Input
4 5 1 2 3 7 5 3 6 7 One 2 5 - - 0 0
Sample Output
3 5 2 3 4
Source
ULM Local
same as the previous question poj2356.
1 #pragmaComment (linker, "/stack:1024000000,1024000000")2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <math.h>7#include <algorithm>8#include <queue>9#include <Set>Ten#include <bitset> One#include <map> A#include <vector> -#include <stdlib.h> - using namespacestd; the #defineMax (a) (a) > (b)? (a): (b) - #defineMin (a) (a) < (b)? (a): (b) - #definell Long Long - #defineEPS 1e-10 + #defineMOD 1000000007 - #defineN 100006 + #defineINF 1e12 A ll N,m; at ll Sum[n]; - ll Vis[n]; - ll A[n]; - ll Tmp[n]; - intMain () - { in while(SCANF ("%i64d%i64d", &n,&m) = =2){ - if(n==0&& m==0){ to Break; + } -memset (SUM,0,sizeof(sum)); the for(LL i=1; i<=m;i++){ * //ll X; $scanf"%i64d",&a[i]);Panax Notoginsengsum[i]=sum[i-1]+A[i]; - } the + Amemset (Vis,0,sizeof(Vis)); thememset (TMP,0,sizeof(TMP)); + for(LL i=1; i<=m;i++){ -ll x=sum[i]%N; $ if(Vis[x]) { $ll y=Tmp[x]; - //printf ("%d\n", i-y); - for(LL j=y+1; j<i;j++){ theprintf"%i64d", j); - }Wuyiprintf"%d\n", i); the Break; - Wu } - if(x==0){ About //printf ("%d\n", I); $ for(LL j=1; j<i;j++){ -printf"%i64d", j); - } -printf"%d\n", i); A Break; + } thevis[x]=1; -tmp[x]=i; $ } the the } the return 0; the}
View Code
Poj 3370 Halloween treats (pigeon nest principle)