Halloween treats

Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets on that day, no matter how many children call on him, so it may happen that a child will get nothing if it is too late. To avoid conflicts, the children have decided they will put all sweets together and then divide them evenly among themselves. From last year's experience of Halloween they know how many sweets they get from each neighbour. Since they care more about justice than about the number of sweets they get, they want to select a subset of the neighbours to visit, so that in sharing every child receives the same number of sweets. They will not be satisfied if they have any sweets left which cannot be divided.

Your job is to help the children and present a solution.

Input

The input contains several test cases.

The first line of each test case contains two integers c and n (1 ≤ c ≤ n ≤ 100000), the number of children and the number of neighbours, respectively. The next line contains n space separated integers a1 , … , an (1 ≤ ai ≤ 100000 ), where ai represents the number of sweets the children get if they visit neighbour i.

The last test case is followed by two zeros.

Output

For each test case output one line with the indices of the neighbours the children should select (here, index i corresponds to neighbour i who gives a total number of ai sweets). If there is no solution where each child gets at least one sweet print "no sweets" instead. Note that if there are several solutions where each child gets at least one sweet, you may print any of them.

Sample Input

4 5
1 2 3 7 5
3 6
7 11 2 5 13 17
0 0

Sample Output

3 5
2 3 4

题意 万圣节要糖,c个人,n个邻居,应该找那几个邻居要糖可以刚好平分。

题解 不存在没有的情况。抽屉原理,用两个数组存第一个存sum[i]%c,第二个存相同mod的位置,然后输出两个相同取余结果之间的位置。

一开始暴力超时,后来空间换时间。

#include<stdio.h>
#include<cstring>
long long a[100010];
long long sum[100010];
int main()
{
int c,n;
while(scanf("%d%d",&c,&n)!=EOF)
{
if(c==0&&n==0)
break;
else
{
memset(a,0,sizeof(a));
long long sum1=0;
int s;
int flag=0;
int k;
for(int i=1;i<=n;i++)
{
int s;
scanf("%d",&s);
sum1+=s;
sum[i]=sum1%c;
}
int i;
a[0]=1;
for(i=1;i<=n;i++)
{
if(a[sum[i]]) break ;
else
a[sum[i]]=i+1;
}
for(int j=a[sum[i]];j<=i-1;j++)
printf("%d ",j);
printf("%d\n",i);
} }
return 0;
}

POJ 3370 Halloween treats(抽屉原理)的更多相关文章

  1. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  2. POJ 3370 Halloween treats(抽屉原理)

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6631   Accepted: 2448 ...

  3. POJ 3370 Halloween treats 鸽巢原理 解题

    Halloween treats 和POJ2356差点儿相同. 事实上这种数列能够有非常多,也能够有不连续的,只是利用鸽巢原理就是方便找到了连续的数列.并且有这种数列也必然能够找到. #include ...

  4. [POJ 3370] Halloween treats

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7143   Accepted: 2641 ...

  5. uva 11237 - Halloween treats(抽屉原理)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/37612503 题目链接:uva 11237 ...

  6. POJ 3370 Halloween treats( 鸽巢原理简单题 )

    链接:传送门 题意:万圣节到了,有 c 个小朋友向 n 个住户要糖果,根据以往的经验,第i个住户会给他们a[ i ]颗糖果,但是为了和谐起见,小朋友们决定要来的糖果要能平分,所以他们只会选择一部分住户 ...

  7. poj 3370 Halloween treats(鸽巢原理)

    Description Every year there is the same problem at Halloween: Each neighbour is only willing to giv ...

  8. 鸽巢原理应用-分糖果 POJ 3370 Halloween treats

    基本原理:n+1只鸽子飞回n个鸽笼至少有一个鸽笼含有不少于2只的鸽子. 很简单,应用却也很多,很巧妙,看例题: Description Every year there is the same pro ...

  9. UVA 11237 - Halloween treats(鸽笼原理)

    11237 - Halloween treats option=com_onlinejudge&Itemid=8&page=show_problem&category=516& ...

随机推荐

  1. Windows下使用nvm管理多个Node.js 版本

    下载 https://github.com/coreybutler/nvm-windows/releases 安装       配置 使用 # nvm install 版本号   # nvm list ...

  2. ORACLE将查询的多条语句拼在一个字段下

    select listagg(字段名,'分隔符') within group (order by 某个字段)

  3. HAProxy负载均衡安装配置

    1.下载HAProxy    http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.22.tar.gz   2. 安装haproxy    #tar z ...

  4. webpack源码之ast简介

    什么是AST 树是一种重要的数据结构,由根结点和若干颗子树构成的. 根据结构的不同又可以划分为二叉树,trie树,红黑树等等.今天研究的对象是AST,抽象语法树,它以树状的形式表现编程语言的语法结构, ...

  5. 分享几道经典的javascript面试题

    这几道题目还是有一点意思的,大家可以研究一番,对自己的技能提升绝对有帮助. 1.调用过程中输出的内容是什么 function fun(n, o) { console.log(o); return { ...

  6. Oracle Form个性化案例(一)

    业务场景: 现有Form A,需通过A中的菜单栏中调用另一Form B,需将某值作为参数传入Form B中:

  7. Garmin APP开发之入门

    Garmin开发-入门 先附上几个已经开发完成的app日历 up down 翻月 start 回到当前月(就差农历了) 秒表和定时器一体app界面比较简单,但是实用,长按菜单键可以切换秒表和定时器,有 ...

  8. Qt安装教程

    一.Qt下载 官网下载链接http://download.qt.io/archive/qt/,下载最新版 5.10 官网的下载网站有的时候可能会抽风,也可以选择国内的镜像下载源http://mirro ...

  9. Merge更新同步一个表

    merge T2   --目标表using T1    --源表 on T1.id=T2.id   --匹配条件 when matched then    --匹配update set [name]= ...

  10. JavaWeb中五种转发方式(转)

    今天本来是想找一下在jsp中实现转发的方式的,无意中看到了一篇文章,然后稍微综合了把服务器端的转发也包括在内.   1. RequestDispatcher.forward() 是在服务器端起作用,当 ...