poj 3370 Halloween treats(鸽巢原理)
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 ( ≤ c ≤ n ≤ ), the number of children and the number of neighbours, respectively. The next line contains nspace separated integers a1 , ... , an ( ≤ ai ≤ ), 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
Sample Output
Source
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
using namespace std;
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 100006
#define inf 1e12
ll n,m;
ll sum[N];
ll vis[N];
ll a[N];
ll tmp[N];
int main()
{
while(scanf("%I64d%I64d",&n,&m)==){
if(n== && m==){
break;
}
memset(sum,,sizeof(sum));
for(ll i=;i<=m;i++){
//ll x;
scanf("%I64d",&a[i]);
sum[i]=sum[i-]+a[i];
} memset(vis,,sizeof(vis));
memset(tmp,,sizeof(tmp));
for(ll i=;i<=m;i++){
ll x=sum[i]%n;
if(vis[x]){
ll y=tmp[x];
//printf("%d\n",i-y);
for(ll j=y+;j<i;j++){
printf("%I64d ",j);
}
printf("%d\n",i);
break; }
if(x==){
//printf("%d\n",i);
for(ll j=;j<i;j++){
printf("%I64d ",j);
}
printf("%d\n",i);
break;
}
vis[x]=;
tmp[x]=i;
} }
return ;
}
poj 3370 Halloween treats(鸽巢原理)的更多相关文章
- POJ 3370 Halloween treats 鸽巢原理 解题
Halloween treats 和POJ2356差点儿相同. 事实上这种数列能够有非常多,也能够有不连续的,只是利用鸽巢原理就是方便找到了连续的数列.并且有这种数列也必然能够找到. #include ...
- POJ 3370 Halloween treats(抽屉原理)
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6631 Accepted: 2448 ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 3370 Halloween treats( 鸽巢原理简单题 )
链接:传送门 题意:万圣节到了,有 c 个小朋友向 n 个住户要糖果,根据以往的经验,第i个住户会给他们a[ i ]颗糖果,但是为了和谐起见,小朋友们决定要来的糖果要能平分,所以他们只会选择一部分住户 ...
- [POJ 3370] Halloween treats
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7143 Accepted: 2641 ...
- POJ 3370 Halloween treats(抽屉原理)
Halloween treats Every year there is the same problem at Halloween: Each neighbour is only willing t ...
- 鸽巢原理应用-分糖果 POJ 3370 Halloween treats
基本原理:n+1只鸽子飞回n个鸽笼至少有一个鸽笼含有不少于2只的鸽子. 很简单,应用却也很多,很巧妙,看例题: Description Every year there is the same pro ...
- [POJ3370]&[HDU1808]Halloween treats 题解(鸽巢原理)
[POJ3370]&[HDU1808]Halloween treats Description -Every year there is the same problem at Hallowe ...
- POJ3370&HDU1808 Halloween treats【鸽巢原理】
题目链接: id=3370">http://poj.org/problem?id=3370 http://acm.hdu.edu.cn/showproblem.php?pid=1808 ...
随机推荐
- Ubuntu 启动器/快捷方式/ 制作 (Eclipse为例)
首先,在路径/usr/share/applications/,中创建eclipse.desktop(如果没有的话) sudo touch /usr/share/applications/eclipse ...
- 04747_Java语言程序设计(一)_第9章_输入和输出流
例9.1一个文件复制应用程序,将某个文件的内容全部复制到另一个文件. import java.io.*; public class Example9_1 { public static void ma ...
- [转]Google2012.9.24校园招聘会笔试题
代码: [cpp] view plaincopy //转载请标明出处,原文地址:http://blog.csdn.net/hackbuteer1/article/details/8017703 boo ...
- C#Http编程
c# 模拟 网页实现12306登陆.自动刷票.自动抢票完全篇(转) 这一篇文章,我将从头到尾教大家使用c#模拟网页面登陆12306网站,自动刷票,选择订票人,到最后一步提交订单.研究过HTTP协议的童 ...
- vps安全设置
适合新手及才接触VPS的朋友们看一下.主要是关于VPS安全方面相关内容的 禁止ROOT登陆 保证安全性. 使用DDoS deflate简单防攻击. iftop Linux流量监控工具: 每日自己主动备 ...
- Linux下用命令格式化U盘
1.找到U盘位置(已挂载) sudo fdisk -l 如图,我的在/dev/sdc4 2.格式化U盘 sudo mkfs -t vfat /dev/sdc4 -t 后面是格式化为哪种文件系统格式,v ...
- BOOST中如何实现线程安全代码
1 需要include <boost/thread.hpp> 2 背景知识请参考<boost程序库完全开发指南>第12章 3 编绎:g++ -o mthread mthread ...
- 9. KNN和Sparse构图
一.前言 图是一种重要的数据结构,本文主要表示图像的无向图.所谓无向图是指,图的节点间通过没有方向的边连接. 无向图的表示: 无向图G=<V,E>,其中: 1.V是非空集合,称为顶点集. ...
- VS2015预览版中的C#6.0 新功能(二)
VS2015预览版中的C#6.0 新功能(一) VS2015预览版中的C#6.0 新功能(三) 自动属性的增强 只读自动属性 以前自动属性必须同时提供setter和getter方法,因而只读属性只能通 ...
- (转) Functions
Functions Functions allow to structure programs in segments of code to perform individual tasks. In ...