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. Hotel booking(spfa+floyd)

    http://acm.hdu.edu.cn/showproblem.php?pid=2992 题意:有n个城市,编号为(1~n),有一些城市中有一些旅店,要求从一个城市到另一个城市不能超过10小时,问 ...

  2. Behavior Designer扩展

    BehaviorManager.instance.Tick(behaviorTree); 卸载update里u3d直接卡死 = = SharedVariable直接赋值会改变他的引用关系,必须用XXX ...

  3. codevs1085数字游戏(环形DP+划分DP )

    1085 数字游戏  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold     题目描述 Description 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单, ...

  4. [Swift通天遁地]九、拔剑吧-(15)搭建具有滑出、视差、3D变形等切换效果的引导页

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  5. AcWing算法基础1.1

    排序 快速排序(快排) 写题的时候用的不多基本都是直接sort ( ),面试可能要手撸快排,上模板 void quick_sort(int q[], int l, int r) { if(l > ...

  6. HDU2564 词组缩写

    2019-06-03 15:00:38 感觉有有种被坑了的感觉,这道题不难,就是一再的W,

  7. mysql 数据去重

    update ptop_investrecord set delflag = 1 where cid  = 250 and uid = 92569  and delflag = 0 and progr ...

  8. HDU 5279 分治NTT 图的计数

    思路: 显然每个子图内都是森林 去掉所有子图1和n都连通且每条大边都存在的情况 直接DP上 NTT优化一波 注意前两项的值.. //By SiriusRen #include <bits/std ...

  9. Python安装distribute包

    从官网https://pypi.python.org/pypi/distribute/0.6.49#downloads上下载distribute包,解压后进入解压文件的目录下,使用 python se ...

  10. scala函数用法

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