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 ...
随机推荐
- istio分布式调用链Jaeger
1.安装 kubectl apply -n istio-system -f https://raw.githubusercontent.com/jaegertracing/jaeger-kuberne ...
- redis 数据类型为list命令整理以及示例
常用来制作队列,当然lpush+rpop也能做栈 #将RPUSH RPUSHX LPUSH LPUSHX一并介绍(具体介绍RPUSH和RPUSHX,因为其实就是插入的方向的区别) RPUSH key ...
- BUG(0):用某位表示特定属性
用某个bit表示特定属性通常有两种方式: 1.指定某个特定的value #define _PAGE_VALID 0x0001 0bit 为 1 时表示此时的page entry是有效的 用法如下,此时 ...
- autohotkey快捷键
;已经基本修复了输入带shift的时候跟输入法中英文切换之间的冲突 SetStoreCapslockMode, off SetKeyDelay, ^CapsLock:: #UseHook ;用这个和下 ...
- How to turn on syntax highlighting in osx
put follow code in ~/.vimrc set ai " auto indenting set history=100 " keep 100 lines of hi ...
- java.lang.SuppressWarnings的注解简介
简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上.作用:告诉编译器忽略指定的警告, ...
- 对SVC和SVR的理解
首先: support vector classify(SVC)支持分类机做二分类的,找出分类面,解决分类问题 support vector regression(SCR)支持回归机做曲线拟合.函数回 ...
- 2018.11.06 bzoj1912: [Apio2010]patrol 巡逻(树形dp)
传送门 一道挺妙的题啊. 对于K==1K==1K==1的直接求树的直径. 对于K==2K==2K==2的先求一次直径,然后考虑到如果两条边加进去形成的两个环重叠就会有负的贡献. 因此把之前那条直径上的 ...
- msyql 主从配置
vim /etc/mysql/my.cnf; # 以下部分一定要配置在[mysqld]后面 [mysqld] log-bin=mysql-bin server-id= //设置数据库服务器唯一ID,这 ...
- LOJ-10099(点双联通)
题目链接:传送门 思路: 如果图是点双联通的,即没有割点,直接从图中随意选两个点即可: 如果有一个割点,删除割点,求连通块的个数即可(在每个连通块内新建一个营救点). 如果有多个割点,则可以通过其他割 ...