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

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

————————————————————————————————————

题意:给你n个数和c,取出一些数,使得这些数字和对c取模为0,输出这些数的位置

解题思路:关键点在c<=n,若前缀和对c取模为0,则直接输出所有数,否则的话,因为c<=n,所以一定会出现同余的情况,同余的两个位置之间所有的数就是答案

注意:POJ可能会卡常数

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f; int a[100005];
int cnt[100005];
int main()
{
int m,n;
while(~scanf("%d%d",&n,&m)&&(m||n))
{ for(int i=1; i<=m; i++)
{
scanf("%d",&a[i]);
}
int sum=0;
memset(cnt,-1,sizeof cnt);
for(int i=1; i<=m; i++)
{
sum+=a[i];
if(sum%n==0)
{
for(int j=1; j<i; j++)
{
printf("%d ",j);
}
printf("%d\n",i);
break;
}
else
{
sum%=n;
if(cnt[sum]>0)
{
for(int j=cnt[sum]+1; j<i; j++)
{
printf("%d ",j);
}
printf("%d\n",i);
break;
}
else
cnt[sum]=i;
}
}
}
return 0;
}

POJ2270&&Hdu1808 Halloween treats 2017-06-29 14:29 40人阅读 评论(0) 收藏的更多相关文章

  1. ZUFE2483 DO IT YOURSELF 2017-05-31 14:41 40人阅读 评论(0) 收藏

    2483: DO IT YOURSELF 时间限制: 2 Sec  内存限制: 128 MB 提交: 8  解决: 3 [提交][状态][讨论版] 题目描述 有四个字符串S,T,tmp,ans,一开始 ...

  2. Hdu1978 How many ways 2017-01-18 14:32 40人阅读 评论(0) 收藏

    How many ways Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total ...

  3. HDU1072 Nightmare(BFS) 2016-07-24 14:02 40人阅读 评论(0) 收藏

    Nightmare Problem Description Ignatius had a nightmare last night. He found himself in a labyrinth w ...

  4. Hadoop入门经典:WordCount 分类: A1_HADOOP 2014-08-20 14:43 2514人阅读 评论(0) 收藏

    以下程序在hadoop1.2.1上测试成功. 本例先将源代码呈现,然后详细说明执行步骤,最后对源代码及执行过程进行分析. 一.源代码 package org.jediael.hadoopdemo.wo ...

  5. iOS正则表达式 分类: ios技术 2015-07-14 14:00 35人阅读 评论(0) 收藏

    一.什么是正则表达式 正则表达式,又称正规表示法,是对字符串操作的一种逻辑公式.正则表达式可以检测给定的字符串是否符合我们定义的逻辑,也可以从字符串中获取我们想要的特定部分.它可以迅速地用极简单的方式 ...

  6. Hdu2181 哈密顿绕行世界问题 2017-01-18 14:46 45人阅读 评论(0) 收藏

    哈密顿绕行世界问题 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  7. MS SQL数据批量备份还原(适用于MS SQL 2005+) 分类: SQL Server 数据库 2015-03-10 14:32 103人阅读 评论(0) 收藏

    我们知道通过Sql代理,可以实现数据库的定时备份功能:当数据库里的数据库很多时,备份一个数据库需要建立对应的定时作业,相对来说比较麻烦: 还好,微软自带的osql工具,比较实用,通过在命令行里里输入命 ...

  8. 不定义JQuery插件,不要说会JQuery 分类: JavaScript 2014-11-24 14:18 155人阅读 评论(0) 收藏

    一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写$("#"),$("."),写了几年就对别人说非常熟悉JQuery.我曾经也是这样的人 ...

  9. Black Box 分类: POJ 栈和队列 2015-08-05 14:07 2人阅读 评论(0) 收藏

    Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8754 Accepted: 3599 Description ...

随机推荐

  1. Informatica_(5)高级应用

    五.高级应用21.任务分区 分区是通过并行处理来提供PowerCenter的执行效率. 分区类型包括:Database partitioning.Hash Auto-keys.Hash User-ke ...

  2. Python 官方文件

    7.2. 文件读写 函数 open() 返回 文件对象,通常的用法需要两个参数:open(filename, mode). >>> f = open('workfile', 'w') ...

  3. 探索未知种族之osg类生物---器官初始化二

    那我们回到ViewerBase::frame函数中来,继续看看为什么osg生命刚刚出生的时候会大哭,除了初始化了eventQuene和cameraManipulator之外还对那些器官进行了初始化.在 ...

  4. Java JMX 监管

    Java JMX 监管 JSR 规范系列目录(https://www.cnblogs.com/binarylei/p/10348178.html) JMX(Java Management Extens ...

  5. Maximum Average Subarray I LT643

    Given an array consisting of n integers, find the contiguous subarray of given length k that has the ...

  6. Java页面中EL的${}与<%= request.getParameter%>有什么区别? el 取不到值

    ${requestScope}操作的是request的作用域,相当于request.getAttribute();不过EL比这个更智能些,它不用强制类型转换就可以拿到了真实对象的值.request.g ...

  7. oracle 导出表

    由于进项目组是跟着dba做事情的,但是没做多久dba走了,差不多就把数据库方面的“杂事”接下来了. 小白一个,只有敬小慎微的操作.经常看到的高水位和低水位的情况,也不敢去乱动. 搞好今天晚上需要跑数据 ...

  8. java保存繁体字到数据库时就报错Incorrect string value: '\xF0\xA6\x8D\x8B\xE5\xA4...' for column 'name' at row 1

    问题分析 普通的字符串或者表情都是占位3个字节,所以utf8足够用了,但是移动端的表情符号占位是4个字节,普通的utf8就不够用了,为了应对无线互联网的机遇和挑战.避免 emoji 表情符号带来的问题 ...

  9. Conda下安装libsvm

    如何在canda下安装libsvm? 版本:Python是2.7 canda2 首先想到的是去Python官网上找libsvm的包,结果并没有. 这是因为libsvm是c语言编写的并不是一个Pytho ...

  10. idea下启动tomcat时,打印的日志中文乱码

    idea2018.2+tomcat8+java8+win10 异常:将编码方式全都修改为UTF-8后,且tomcat的VM启动参数中配置了:-Dfile.encoding=UTF-8.导致控制台日志打 ...