Halloween treats

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 434    Accepted Submission(s): 134
Special Judge

Problem Description
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
 
Source
 
 

#include <stdio.h>
#include <string.h>

int a[101000],b[101000];

int main()
{
    int n,c;
    while(scanf("%d %d",&c,&n),c||n)
    {
        int i,j,sum,begin,end;
        memset(b,0,sizeof(b));
        for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
        sum=0;
        for(i=1;i<=n;i++)
        {
            sum=(sum+a[i])%c;
            if(sum==0)
            {
                begin=1;
                end=i;
                break;
            }
            else if(!(b[sum]))
            {
                b[sum]=i;
            }
            else
            {
                begin=b[sum]+1;
                end=i;
            }
        }
        for(i=begin;i<=end;i++)
        {
            if(i<end)
            printf("%d ",i);
            else
            printf("%d\n",i);
        }
    }
    return 0;
}

//组合数学之抽屉原理   相关题目 poj 2356

 

【ACM】hdu_1808_Halloween treats_201308132022的更多相关文章

  1. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  2. 【ACM】HDU1008 Elevator 新手题前后不同的代码版本

    [前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...

  3. 【ACM】魔方十一题

    0. 前言打了两年的百度之星,都没进决赛.我最大的感受就是还是太弱,总结起来就是:人弱就要多做题,人傻就要多做题.题目还是按照分类做可能效果比较好,因此,就有了做几个系列的计划.这是系列中的第一个,解 ...

  4. 【ACM】那些年,我们挖(WA)过的最短路

    不定时更新博客,该博客仅仅是一篇关于最短路的题集,题目顺序随机. 算法思想什么的,我就随便说(复)说(制)咯: Dijkstra算法:以起始点为中心向外层层扩展,直到扩展到终点为止.有贪心的意思. 大 ...

  5. 【ACM】不要62 (数位DP)

    题目:http://acm.acmcoder.com/showproblem.php?pid=2089 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新 ...

  6. 【Acm】八皇后问题

    八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题. 其解决办法和我以前发过的[算法之美—Fire Net:www.cnblogs.com/lcw/p/3159414.html]类似 题目:在8 ...

  7. 【ACM】hud1166 敌兵布阵(线段树)

    经验: cout 特别慢 如果要求速度 全部用 printf !!! 在学习线段树 内容来自:http://www.cnblogs.com/shuaiwhu/archive/2012/04/22/24 ...

  8. 【acm】杀人游戏(hdu2211)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2211 杀人游戏 Time Limit: 3000/1000 MS (Java/Others)    M ...

  9. 【ACM】How many prime numbers

    http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=1&problemid=2 #inclu ...

随机推荐

  1. 同一个Tomcat下不同项目之间的session共享

    最近发现项目运行过程中经常会抛出一个 NullPointerException的异常,经检查发现异常出现的地方是日志模板,一阵检查,正常无误 (把所有记录日志的地方都点了一遍,心里是崩溃的),万念俱灰 ...

  2. PCB Genesis 外形加内角孔实现方法

    在PCB工程制作CAM时,经常会遇到外形拐角处直角的,而客户对内角是要求,比如最大内角要求R0.5mm或者不接受内角, 但成型方式为铣方式,又不是啤板成型,那怎么处理才可以达到要求效果呢,在这里介绍2 ...

  3. SpringBoot集成Redis来实现缓存技术方案

    概述 在我们的日常项目开发过程中缓存是无处不在的,因为它可以极大的提高系统的访问速度,关于缓存的框架也种类繁多,今天主要介绍的是使用现在非常流行的NoSQL数据库(Redis)来实现我们的缓存需求. ...

  4. RHEL6.5 设置yum,IP地址,解压缩

    系统运维 www.osyunwei.com 温馨提醒:qihang01原创内容©版权所有,转载请注明出处及原文链接 服务器相关设置如下: 操作系统:RHEL 6.5 64位 IP地址:192.168. ...

  5. nginx + php-fpm 运行原理

    一.关于nginx 1.1 简单认知 我们都知道nginx 是web服务器. 也知道 用户访问时通过ip和端口访问 nginx. 那么nginx 是如何 通过php 获取数据并返回数据的呢? 1.2 ...

  6. .net 必看书籍1

    我们2个网站运营群,有很多技术高手,同时也有大部分技术新人,如何从传统asp转到.net,从传统table转到div+css布局,从传统技术转到ajax,从小型程序转到高性能并发的大型程序,我花了2小 ...

  7. hbuilder中的 http://www.w3.org/TR/html4/frameset.dtd

    <!-- This is the HTML 4.01 Frameset DTD, which should be used for documents with frames. This DTD ...

  8. scala函数用法

    直接上代码. package com.test.scala.test object Function { def main(args: Array[String]): Unit = { println ...

  9. 项目管理01--使用Maven构建项目(纯干货)

    目录 1. Maven基础知识 2. Maven实战.开发.测试.打包.部署一个Web项目 一.Maven基础知识 Maven坐标 Maven提供了一个中央仓库,里面包含了大量的开源软件的jar包,只 ...

  10. python 字典 get方法

    在做项目的过程中,遇到了一个问题,数据保存到字典中,后来发现数据不对,排查了字典的构建过程,是OK的,后来怀疑是别的部分共用了这一个字典,排查代码,发现这里应该是有问题的. score = None ...