POJ2270&&Hdu1808 Halloween treats 2017-06-29 14:29 40人阅读 评论(0) 收藏
| 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) 收藏的更多相关文章
- 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,一开始 ...
- 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 ...
- 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 ...
- Hadoop入门经典:WordCount 分类: A1_HADOOP 2014-08-20 14:43 2514人阅读 评论(0) 收藏
以下程序在hadoop1.2.1上测试成功. 本例先将源代码呈现,然后详细说明执行步骤,最后对源代码及执行过程进行分析. 一.源代码 package org.jediael.hadoopdemo.wo ...
- iOS正则表达式 分类: ios技术 2015-07-14 14:00 35人阅读 评论(0) 收藏
一.什么是正则表达式 正则表达式,又称正规表示法,是对字符串操作的一种逻辑公式.正则表达式可以检测给定的字符串是否符合我们定义的逻辑,也可以从字符串中获取我们想要的特定部分.它可以迅速地用极简单的方式 ...
- Hdu2181 哈密顿绕行世界问题 2017-01-18 14:46 45人阅读 评论(0) 收藏
哈密顿绕行世界问题 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- MS SQL数据批量备份还原(适用于MS SQL 2005+) 分类: SQL Server 数据库 2015-03-10 14:32 103人阅读 评论(0) 收藏
我们知道通过Sql代理,可以实现数据库的定时备份功能:当数据库里的数据库很多时,备份一个数据库需要建立对应的定时作业,相对来说比较麻烦: 还好,微软自带的osql工具,比较实用,通过在命令行里里输入命 ...
- 不定义JQuery插件,不要说会JQuery 分类: JavaScript 2014-11-24 14:18 155人阅读 评论(0) 收藏
一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写$("#"),$("."),写了几年就对别人说非常熟悉JQuery.我曾经也是这样的人 ...
- Black Box 分类: POJ 栈和队列 2015-08-05 14:07 2人阅读 评论(0) 收藏
Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8754 Accepted: 3599 Description ...
随机推荐
- 25.mysql中的常用工具
25.mysql中的常用工具25.1 mysql客户端连接工具跳转至mysql安装目录下的bincd C:\Program Files\MySQL\MySQL Server 5.7\binmac下cd ...
- PYthon end
关键字end可以用于将结果输出到同一行,或者在输出的末尾添加不同的字符. # -*- coding:utf-8 -*- count = 1 while count <=5: i=1 while ...
- OpenGL3D图形、旋转、纹理、键盘移动、光照、滤波、透明(完整) 转自http://www.cnblogs.com/tiandsp/archive/2012/01/23/2329049.html
#include <windows.h> // Windows的头文件 #include <stdio.h> #include <gl\gl.h> // OpenG ...
- PHP Jquery 代码操作 内容 属性 样式 事件 Json数据
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- spring boot 整合 RabbitMq (注解)
1.增加rabbitmq的依赖包 <!-- ampq 依赖包 --> <dependency> <groupId>org.springframework.boot& ...
- VS2010工程结构及其瘦身策略
VS2010工程结构: 我们以在VS2010上利用MFC创建的单文档应用程序HelloWorld的文件结构为例,简述VS2010应用程序工程中文件的组成结构. 1.解决方案相关文件 解决方案相关文件包 ...
- 大牛的距离(笑cry)精简算法
在一条数轴上有N头牛在不同的位置上,每头牛都计算到其它各头牛的距离.求这n*(n-1)个距离的总和.1<= N <= 10000.每头牛所在位置是一个范围在0到1,000,000,000之 ...
- [Python] Python教程
http://www.runoob.com/python/python-tutorial.html
- java如何实现发邮件功能。
http://blog.sina.com.cn/s/blog_59ca2c2a01013800.html http://www.cnblogs.com/xdp-gacl/p/4216311.html
- centos下安装配置jetty
下载jdk-8u144-linux-x64.tar.gz # tar -zxvf jdk-8u144-linux-x64.tar.gz # mv jdk1.8.0_144 /usr/java/ # u ...