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 ...
随机推荐
- hdu 5312 Sequence(数学推导+线性探查(两数相加版))
Problem Description Today, Soda has learned a sequence whose n-th (n≥) item )+. Now he wants to know ...
- 应对Deadline,时间怎么安排?
问题定义 项目过程中,每项任务都是有时间要求的,一般体现为"截止时间".即Deadline. 怎样安排时间,才干在Deadline之前完毕任务呢? 有效实践 错误做法 在Deadl ...
- drwtsn32.exe 遇到问题须要关闭。我们对此引起的不便表示抱歉
我的机器老是这样.启动起来就有这个... 那位高手能告诉我这是怎么会事.故障的原因以及解决的办法. 最佳答案 drwtsn32.exe是windows的一项磁盘检查程序,同一时候也是鸡肋程序,最好的办 ...
- IOS中对图片进行重绘处理的方法总结
一.CGImageRef是什么 CGImageRef是定义在QuartzCore框架中的一个结构体指针,用C语言编写.在CGImage.h文件中,我们可以看到下面的定义: ? 1 typedef st ...
- Filter简单介绍
一.简单介绍 Filter也称为过滤器,WEB开发者通过Filter技术.对webserver管理的全部web资源:比如Jsp, Servlet, 静态图片文件或静态 html 文件等进行拦截.从而实 ...
- 推荐几本不错的ASP.NET MVC书
以前主要是做PHP应用的,由于工作需要,捡起来.NET, 特别是新技术层出不穷,找了几本书看,个人感觉还不错,网上也有电子版的下载 一. ASP.NET MVC4 Web 编程 O'Reilly出版社 ...
- CSS---------------之文本类型
通过font来改变文本,主要从以下几个方面 字体加粗,字体的风格:斜体和字体变形:小型大写字母 字体的大小 行高 字体 示例如下 p{font:italic 75%/125% "Comic ...
- 在IIS Express中调试时无法读取配置文件
在IIS Express中调试代码时,如果出现“无法读取配置文件”的问题(如图),这种情况是IIS Express的“applicationhost.config”配置文件中的映射关系出了问题[ps: ...
- git 分支的基本操作
git分支的基本操作. 创建私有分支: $git branch branchName commitID $git checkout -b branchName commitID 注意: ...
- 502 Proxy Error。The ISA Server denied the specified Uniform Resource Locator (URL).
问题:部署好项目,在IE地址栏输入http://localhost/myweb/index.aspx,回车后报错: 解释: 试图访问的页面出现问题,无法显示此页面. 尝试下列: 刷新页: 单击“刷 ...