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.

InputThe 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 a 1 , ... , a n (1 ≤ a i ≤ 100000 ), where a i represents the number of sweets the children get if they visit neighbour i.

The last test case is followed by two zeros.

OutputFor 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 a i 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
题解: 鸽巢原理
参考代码:
 #include<iostream>
#include<cstdio>
using namespace std;
const int maxn=1e5+;
int c,n,a[maxn],temp[maxn];
int main()
{
while(~scanf("%d%d",&c,&n),c+n)
{
for(int i=;i<=n;i++) scanf("%d",a+i),temp[i]=;
int sum=;
for(int i=;i<=n;i++)
{
sum=(sum+a[i])%c;
if(sum==)
{
for(int j=;j<i;j++) printf("%d ",j);
printf("%d\n",i);
break;
}
else if(temp[sum])
{
for(int j=temp[sum]+;j<i;j++) printf("%d ",j);
printf("%d\n",i);
break;
}
else temp[sum]=i;
}
}
return ;
}

HDU 1808 Halloween treats的更多相关文章

  1. HDU 1808 Halloween treats(抽屉原理)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=1808 Problem Description Every year there is the same ...

  2. Halloween treats HDU 1808 鸽巢(抽屉)原理

    Halloween treats Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

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

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

  4. [POJ 3370] Halloween treats

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

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

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

  6. POJ2270&&Hdu1808 Halloween treats 2017-06-29 14:29 40人阅读 评论(0) 收藏

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8565   Accepted: 3111 ...

  7. [POJ3370]&[HDU1808]Halloween treats 题解(鸽巢原理)

    [POJ3370]&[HDU1808]Halloween treats Description -Every year there is the same problem at Hallowe ...

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

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

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

    Halloween treats Every year there is the same problem at Halloween: Each neighbour is only willing t ...

随机推荐

  1. IDEA快捷键汇总

    [常用] Ctrl+Shift + Enter,语句完成 "!",否定完成,输入表达式时按 "!"键 Ctrl+E,最近的文件 Ctrl+Shift+E,最近更 ...

  2. 一文看懂 K8s 日志系统设计和实践

    上一篇中我们介绍了为什么需要一个日志系统.为什么云原生下的日志系统如此重要以及云原生下日志系统的建设难点,相信DevOps.SRE.运维等同学看了是深有体会的.本篇文章单刀直入,会直接跟大家分享一下如 ...

  3. Linux入门之简介

    1.啥是linux? Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和Unix的多用户.多任务.支持多线程和多CPU的操作系统. 它能运行主要的Unix工具软件.应用程序 ...

  4. 力扣(LeetCode)验证回文串 个人题解

    给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 示例 1: 输入: "A man, a plan, a c ...

  5. 领扣(LeetCode)删除链表中的节点 个人题解

    请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点,你将只被给定要求被删除的节点. 现有一个链表 -- head = [4,5,1,9],它可以表示为: 4 -> 5 -> 1 - ...

  6. 发送大数据时,PDU的问题?

    昨天发现通过 Ice发送请求传递一个大块数据时,当请求的体积大于1.2M后,直接抛出异常Connection Lost,对方peer或是断开了.通过防火墙配置排查,以及对同一网络同一机器的php服务p ...

  7. 2C 还是 2B,跟找工作有什么关系?

    通常,我们会把公司的业务类型分成以下几种: 2C,to Customer,指面向个人客户的业务,即将公司的产品或服务销售给个人,通常做出购买决策的个人也是使用产品或服务的用户.举例说明,像 BAT 发 ...

  8. SpringBoot源码学习系列之SpringMVC自动配置

    目录 1.ContentNegotiatingViewResolver 2.静态资源 3.自动注册 Converter, GenericConverter, and Formatter beans. ...

  9. Alibaba Nacos 学习(四):Nacos Docker

    Alibaba Nacos 学习(一):Nacos介绍与安装 Alibaba Nacos 学习(二):Spring Cloud Nacos Config Alibaba Nacos 学习(三):Spr ...

  10. 从壹开始 [ Ids4实战 ] 之六 ║ 统一角色管理(上)

    前言 书接上文,咱们在上周,通过一篇<思考> 性质的文章,和很多小伙伴简单的讨论了下,如何统一同步处理角色的问题,众说纷纭,这个我一会儿会在下文详细说到,而且我最终也定稿方案了.所以今天咱 ...