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. IDEA报错,注解标红,提示Cannot resolve symbol xxx

    一般都是jar包没导进来,可以先看一下setting里maven配置的路径对不对

  2. 【BZOJ1939】[Croatian2010] Zuma(动态规划)

    题目: BZOJ1939(权限题) 分析: 这题很容易看出是DP,但是状态和转移都不是很好想-- 用\(dp[l][r][c]\)表示在\(l\)前面已经新加了\(c\)个和\(l\)一样的弹子时,使 ...

  3. android ListView,GridView 设置某一项显示位置

    在项目中有时会用到,当使用 listview  想让它显示某一项,当它又不在前面的位置,可以 使用 //让某一项显示出来(否则可能不在当前) listview.setSelection(positio ...

  4. 如何卸载系统自带的Microsoft Office

    (1)首先.在C盘删除office文件夹. (2)删除注册表 1)开始菜单-->运行-->regedit进入注册表 (window+r  -->) 2)在注册表里找到HKEY_CUR ...

  5. HTML CSS, JavaScript 计算器

    效果图: 代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...

  6. c++枚举变量初始值

    #include <iostream> // std::cout, std::boolalpha, std::noboolalpha enum foo { c = -1, a = 1, b ...

  7. THREE.DecalGeometry(转载)

    function getDecalGeometry(position, direction){ var decalGeometry = new THREE.DecalGeometry( earthMe ...

  8. C#使用Win32函数的一些类型转换

    C#在访问Win 32 Api时需要处理C 结构与C#结构的映射,这在MSDN以及许多Blog上都可以找到参考的资料.Win 32 中有一些定义复杂的Struct,这些结构体拥有长度固定的数组或者一些 ...

  9. 微信小程序video

    1.video是原生组件原生组件的层级是最高的,想要覆盖在video上,只能用cover-view 和 cover-image 组件,这2个可以无限嵌套.适用场景:给视频加标题: 2.检测video播 ...

  10. js案例分析

    名字取的高大上,其实只是我平时上网浏览遇到的一些我感觉还不错的小题目,再加上我或者是我在网上找到的一些理解,就保存到这里了. 2019/4/2  最新开了个新坑,是一个javascipt30的一些案例 ...