Halloween treats

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1097    Accepted Submission(s): 435
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
 
Recommend
linle   |   We have carefully selected several similar problems for you:  1802 1807 1806 1804 1801 
 
鸽巢原理的意思是一定存在一个连续的区间,满足题目要求(是n的倍数)
所以我们只需要求一段连续区间的和是否是n的倍数
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
typedef long long ll;
ll vis[maxn], a[maxn];
int main() {
std::ios::sync_with_stdio(false);
ll n, m;
while( cin >> n >> m ) {
if( !n && !m ) {
break;
}
ll sum = 0, t;
memset( vis, 0, sizeof(vis) );
for( ll i = 1; i <= m; i ++ ) {
cin >> a[i];
}
for( ll i = 1; i <= m; i ++ ) {
sum += a[i];
t = sum%n;
if( t == 0 ) {
for( ll j = 1; j < i; j ++ ) {
cout << j << " ";
}
cout << i << endl;
break;
} else if( vis[t] ) { //如果余数在前面出现过,现在又出现了,则中间一定加了n的倍数
for( ll j = vis[t]+1; j < i; j ++ ) {
cout << j << " ";
}
cout << i << endl;
break;
}
vis[t] = i;
}
}
return 0;
}

  

Halloween treats HDU 1808 鸽巢(抽屉)原理的更多相关文章

  1. [POJ3370]&[HDU1808]Halloween treats 题解(鸽巢原理)

    [POJ3370]&[HDU1808]Halloween treats Description -Every year there is the same problem at Hallowe ...

  2. HDU 1205 鸽巢原理

    #include <bits/stdc++.h> using namespace std; long long abs_(long long a,long long b) { if(a&g ...

  3. HDU 5776 sum(抽屉原理)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=5776 Problem Description Given a sequence, you're ask ...

  4. hdu 1205 吃糖果 (抽屉原理<鸽笼原理>)

    吃糖果Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submissi ...

  5. HDU 1808 Halloween treats(抽屉原理)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=1808 Problem Description Every year there is the same ...

  6. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  7. POJ3370&amp;HDU1808 Halloween treats【鸽巢原理】

    题目链接: id=3370">http://poj.org/problem?id=3370 http://acm.hdu.edu.cn/showproblem.php?pid=1808 ...

  8. POJ 3370 Halloween treats 鸽巢原理 解题

    Halloween treats 和POJ2356差点儿相同. 事实上这种数列能够有非常多,也能够有不连续的,只是利用鸽巢原理就是方便找到了连续的数列.并且有这种数列也必然能够找到. #include ...

  9. POJ 3370 Halloween treats( 鸽巢原理简单题 )

    链接:传送门 题意:万圣节到了,有 c 个小朋友向 n 个住户要糖果,根据以往的经验,第i个住户会给他们a[ i ]颗糖果,但是为了和谐起见,小朋友们决定要来的糖果要能平分,所以他们只会选择一部分住户 ...

随机推荐

  1. 实用小工具推荐 OpenWrite

    [实用小工具推荐]给技术同学们推荐一款比较好用的工具,可以实现一稿多发,主流的技术渠道基本涵盖了:https://www.openwrite.cn/ 因为工作的关系,认识了很多做技术公众号的小伙伴,同 ...

  2. C语言编程入门之--第五章C语言基本运算和表达式-part1

    导读:程序要完成高级功能,首先要能够做到基本的加减乘除.本章从程序中变量的概念开始,结合之前学的输出函数和新介绍的输入函数制作简单人机交互程序,然后讲解最基础的加减法运算,自制简单计算器程序练手. 5 ...

  3. 3PHP如何用PDO的连接方式方式导出mysql数据

    首先连接mysql,具体看上一篇 接下来在try{}中加入以下代码 $query="select * from 你的数据表名称"          //$query的内容给个SQL ...

  4. Unity通过NTP获取网络时间

    最初通过qq时间服务器获得时间,经常出现有网络也获取失败的情况. 后面寻找解决办法,查找资料终于发现通过ntp时间服务器获取网络时间的方法.   首先游戏开始获得初始化网络时间,通常只获取一次,其他时 ...

  5. SpringMVC的流程

    Springmvc的流程 1.用户发送请求至前端控制器DispatcherServlet 2.DispatcherServlet收到请求后,调用HandlerMapping处理映射器,请求获取Hand ...

  6. Java连载14-补码简介&浮点型整数

    一.补码简介 1.计算机中的符号数有三种表示方式,即为:原码.反码.补码.三种表示方法均有符号位和数值位,符号位都是0表示正数,符号位都是1表示负数. 2.计算机中的数字的存储方式:在计算机系统中,数 ...

  7. HTML/CSS:导航栏水平和垂直

    1.垂直导航栏 导航栏 = 链接列表导航栏基本上是一个链接列表,因此使用 <ul> 和 <li> 元素是非常合适的.如需构建垂直导航栏,我们只需要定义 <a> 元素 ...

  8. maven3实战之仓库

    maven3实战之仓库(maven仓库分类) maven3实战之仓库(maven仓库分类) ---------- 对于maven来说,仓库只分为两类:本地仓库和远程仓库.当maven根据坐标寻找构件的 ...

  9. 第一次亲密接触——二狗子初识 CDN

    二狗子是国内知名XXX大学的在校学生,作为一名编程爱好者,他利用业余时间搭建了一个网站,把平时的学习心得和技术分享全都 PO 在自己的网站上.渐渐地,二狗子的网站因为文章质量高,技术分享全面,受到了很 ...

  10. GOF23-工厂模式

    1.什么是工厂模式 就是实现创建者与调用者分离,工厂模式的核心(灵魂)其实就是:分工.   2.工厂模式有哪些 简单工场模式(静态工厂) 简单工厂模式也叫静态工厂模式,就是工厂类一般使用静态方法,通过 ...